For the following code snippet and the result, since Margins=True
gives the average of both values of a row, it calculates it wrong. Is there any explanation of it?
# Print the mean weekly_sales by department and type; fill missing values with 0s; sum all rows and cols
print(sales.pivot_table(values="weekly_sales", index="department", columns="type", fill_value=0,margins=True))
And the result is:
<code>type A B All
department
1 30961.725 44050.627 32052.467
2 67600.159 112958.527 71380.023
3 17160.003 30580.655 18278.391
4 44285.399 51219.654 44863.254
5 34821.011 63236.875 37189.000
... ... ... ...
96 21367.043 9528.538 20337.608
97 28471.267 5828.873 26584.401
98 12875.423 217.428 11820.590
99 379.124 0.000 379.124
All 23674.667 25696.678 23843.950
</code>
<code>type A B All
department
1 30961.725 44050.627 32052.467
2 67600.159 112958.527 71380.023
3 17160.003 30580.655 18278.391
4 44285.399 51219.654 44863.254
5 34821.011 63236.875 37189.000
... ... ... ...
96 21367.043 9528.538 20337.608
97 28471.267 5828.873 26584.401
98 12875.423 217.428 11820.590
99 379.124 0.000 379.124
All 23674.667 25696.678 23843.950
</code>
type A B All
department
1 30961.725 44050.627 32052.467
2 67600.159 112958.527 71380.023
3 17160.003 30580.655 18278.391
4 44285.399 51219.654 44863.254
5 34821.011 63236.875 37189.000
... ... ... ...
96 21367.043 9528.538 20337.608
97 28471.267 5828.873 26584.401
98 12875.423 217.428 11820.590
99 379.124 0.000 379.124
All 23674.667 25696.678 23843.950
I searched whole the internet and found just a duplicate topic on this website.