I have two pandas dataframe, one has columns a, b, c & other has column a, b, d.
df1
id month c
1 1 TE
2 1 TE
1 1 NTE
2 1 NTE
df2
id month price
1 1 4
2 1 6
I want to merge these dataframes on id & month columns combinedly. so i did following -
df1.merge(df2, how='left', left_on=['id', 'month'], right_on=['id', 'month'])
results of above code is as expected. now, what i want is, after merge, only one pair of id & month should have price, other pair have price as 0
so the result should be like
id month c price
1 1 TE 4
2 1 TE 6
1 1 NTE 0
2 1 NTE 0
Above can be done, while calling a check one each row, which i think is very expensive, n*n complexity.
Any leads with less expense is most welcome.