简体   繁体   中英

Combine three Pandas Pivot Tables with different column numbers

I have three pandas pivot_tables:

# First Pivot Table

# Total Sales of Product 1
Month
Branch    1       2       3
1        100.00   80.00  50.00 
2        200.00   50.00  60.00
3        250.00   90.00  65.00 

# Second Pivot Table

# Total Commission of Product 1
Month
Branch    1       2       3
1        10.00   8.00  5.00 
2        20.00   5.00  6.00
3        25.00   9.00  6.50

# Third Pivot Table

# Sales Count (general including other products)
Month
Branch    2     3
1         5     5 
2         1     6
3         3     6

when I try combine the three pivoted dataframes, I'm getting the error: "cannot convert float NaN to integer" .

The command I tried:

dfResult = dfTotalSales.append(dfCommission).append(dfSalesCount)

Besides the error above...

How can I combine them and return a new column with the average of Net Sales total?

Formula: (Total Sales - Commission) / Sales account

Thanks in advance.

is your data is like the following in branch 1 first month sales is 100 in branch 2 first month sales is 80

if yes than I think sales count is not present for the branch 1. ie according to my understanding the sales count is given only for branch 2 and 3.

so while processing he tried to fill null value, but other than sales count the data is integer. so it can not convert the float to int.

so make all in int or float then try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM