I have 2 dataframes.
First one, lets call it requests and df1.
id number val
0 09876 1
1 12345 2
2 23456 3
3 34567 4
and then I have another dataframe, lets call it receipts and df2.
id item ref receipt
0 shoes 34567 #Pos32
1 socks 12345 #Pos33
Requests will be my main dataframe that I will be working with and adding data.
I need to add a new columns in requests, based on some data from receipts.
If df2 contains a ref which equals the ‘number’ from df1 I want to create a new column in df1 called receipt with the allocated receipt number.
I tried the following using Numpy,
df1[‘receipt'] = np.where(df1[’number'] == df2[‘ref'], df2[‘receipt'], ‘')
but I’m greeted with ValueError: Can only compare identically-labeled Series objects, which makes sense cause the dataframes will not have the same order.
Any other suggestions how to get past this?
at the end I'd like my dataframe to look something like this
id number val receipt
0 09876 1
1 12345 2 #Pos2
2 23456 3
3 34567 4 #Pos1
Thanks
mapif join on one column and returning one column, otherwise you want tomergeyour two dataframes.