Python Forum
How to obtain values under All when the margins of pivot_table is set to True?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to obtain values under All when the margins of pivot_table is set to True?
#1
Hi, anybody knows how the values under All (both row and column) were calculated. I heard that by setting margins equals to True, the values under All are the group statistics. I added the values in the first column and divided by 6, I got 2.4975635 but privot_table gave 2.668874. Similarly, I calculated the average on the first row (2+2.222222)/2 = 2.111111 but pivot_table gave 2.166667.

In [66]: tips.pivot_table(['tip_pct', 'size'], index=['time', 'day'], columns='s
    ...: moker', margins=True)                                                  
Out[66]: 
                 size                       tip_pct                    
smoker             No       Yes       All        No       Yes       All
time   day                                                             
Dinner Fri   2.000000  2.222222  2.166667  0.139622  0.165347  0.158916
       Sat   2.555556  2.476190  2.517241  0.158048  0.147906  0.153152
       Sun   2.929825  2.578947  2.842105  0.160113  0.187250  0.166897
       Thur  2.000000       NaN  2.000000  0.159744       NaN  0.159744
Lunch  Fri   3.000000  1.833333  2.000000  0.187735  0.188937  0.188765
       Thur  2.500000  2.352941  2.459016  0.160311  0.163863  0.161301
All          2.668874  2.408602  2.569672  0.159328  0.163196  0.160803
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 1,091 Jan-06-2023, 10:53 PM
Last Post: haihal
  Graph that shows predicted vs true values donnertrud 1 2,539 Jan-28-2020, 07:47 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020