May-27-2020, 08:52 PM
I figured how to use the merge command (sorta). The following code combines both df1 and df2 together- (I added left/right on because this is the column I need to merge on). Works great but I dont want to merge all columns from both dataframes.
Ultimately, yes I do want to merge on column C from df1 to df2.."but" I want to keep df1 intact but ONLY bring in column D from df2 into df1. I do not want to bring in all columns from df2. Please look below, this is exactly what I want to happen.
CURRENT STATE
df1
A | B | C | D
-----------------------------------
grapes|berry | apples | mango
df2
A | B | C | D
-----------------------------------
veggies|meat | drinks | apple_types
FUTURE STATE
df1
A | B | C | D | E |
-----------------------------------
grapes|berry | apples | mango |apple_types
Thank you for your help. I am going crazy on this.
pd.merge(df1, df2, left_on='apples', right_on='drinks'). I read online and looked at alot of youtube videos and people do associate vlookup with merge. But in all examples they end up bringing in all columns, which I do not want to happen.
Ultimately, yes I do want to merge on column C from df1 to df2.."but" I want to keep df1 intact but ONLY bring in column D from df2 into df1. I do not want to bring in all columns from df2. Please look below, this is exactly what I want to happen.
CURRENT STATE
df1
A | B | C | D
-----------------------------------
grapes|berry | apples | mango
df2
A | B | C | D
-----------------------------------
veggies|meat | drinks | apple_types
FUTURE STATE
df1
A | B | C | D | E |
-----------------------------------
grapes|berry | apples | mango |apple_types
Thank you for your help. I am going crazy on this.