Reputation: 35
I'm attempting to merge two dataframes using two columns as keys: "Date" and "Instrument"
Here is my code:
merge_df = pd.merge(df1 , df2, how='outer', left_on=['Date','Instrument'], right_on = ['Date','Instrument'])
You'll notice that the row in each dataframe has the same instrument and date value: AEA000201011 & 2008-01-31.
The merged dataframe is stacking the two rows instead of combining them:
I have ensured that the dataframe key columns dtypes match:
Any advice would be much appreciated!
Upvotes: 0
Views: 46
Reputation: 69
Man I wish I could use add comment section.
Even though you've probably already tried, have tried to use "left" or "right" instead of "outer" Or for once check them like
df1["Instrument"].iloc[0] == df2["Instrument"].iloc[0]
Maybe they got some invisible chars in them. If it's like that you can try using strip() functions. Nothing other than these comes to my mind.
Upvotes: 2