Join Two Dataframes With No Common Columns For Calculations
I'm trying to do a calculation based on information that I have in two different datasets. I need all the information for the first dataframe repetead as many times as the informa
Solution 1:
It seems you need cross join
:
df = pd.merge(df1.assign(A=1), df2.assign(A=1), on='A').drop('A', 1)
print (df)
name price currency value
0 A 1 Dollar 1
1 A 1 Euro 2
2 B 2 Dollar 1
3 B 2 Euro 2
And then if necessary muliple columns price
and value
:
df['value'] *= df['price']
print (df)
name price currency value
0 A 1 Dollar 1
1 A 1 Euro 2
2 B 2 Dollar 2
3 B 2 Euro 4
Post a Comment for "Join Two Dataframes With No Common Columns For Calculations"