'How to calculate a formula contain different columns from different dataframes
I have to calculate "totalAmountCollected + endingReceivables - totalSalesDone"
All three columns from three dataframes. There is one common column in three dataframes is clientCode.
How to achieve that?
Solution 1:[1]
df = df1.merge(df2, on="clientCode").merge(df3, on="clientCode").fillna(0)
df['result'] = df.totalAmountCollected + df.endingReceivables - df.totalSalesDone
If the clients population is not the same in all three dataframes, you may want to consider left or outer joins.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | John Giorgio |
