Python Pandas Pivot Table Index location Percentage calculation on Two columns

pivot table for year on year

This is a quick example of how to use pivot_table,  to calculate year on year percentage sales .

In [162]:

 

In [163]:

 

In [164]:

 

Out[164]:
First Name Last Name Sex Phone Fax Email Address Booking Date Departure Date Arrival Date Address1 Number of Passengers Total Cost Currency Numeric Code Company website Flight ID Number Flight Booking ID Insurance AFP Flight Name Age
0 Ellis Harris m 077 5665 3370 077 5665 3373 Ellis.E.Harris@mailinator.com 2012-12-18 2011-07-16 2000-08-23 63 Hull Road 2 983 710 http://qvc.com 4111113236285560 1 16 62 ZAR 62
1 Aaron Field m 079 6068 9016 079 6068 9015 Aaron.A.Field@mailinator.com 2014-10-28 2005-02-26 2000-07-30 42 Russell Rd 9 2452 710 http://msnbc.com 4111110402728960 2 83 38 ZAR 44
2 Archie Kaur m 070 3056 9804 070 3056 9809 Archie.M.Kaur@spambob.com 2003-11-17 2000-12-05 2007-03-07 10 Southend Avenue 8 1710 710 http://ap.org 4111110879255550 3 54 58 ZAR 60
3 Bradley Middleton m 070 0765 7814 070 0765 7816 Bradley.A.Middleton@dodgeit.com 2013-07-18 2011-02-26 2015-10-25 32 Pier Road 6 518 710 http://tripadvisor.com 4111111855573320 4 72 43 ZAR 66
4 Evan Reeves m 070 8266 4451 070 8266 4458 Evan.A.Reeves@dodgeit.com 2006-07-20 2006-06-20 2001-02-25 75 Moulton Road 7 1943 710 http://aliexpress.com 4111113022178850 5 68 52 ZAR 38

5 rows × 25 columns

In [165]:

 

Out[165]:
In [166]:

 

Out[166]:
In [167]:

 

In [168]:

 

Out[168]:
First Name Last Name Sex Phone Fax Email Address Booking Date Departure Date Arrival Date Address1 Number of Passengers Total Cost Currency Numeric Code Company website Flight ID Number Flight Booking ID Insurance AFP Flight Name Age
281 Bradley Hope m 078 8099 3168 078 8099 3163 Bradley.G.Hope@trashymail.com 2016-01-31 2010-09-11 2012-02-10 36 Chapel Lane 5 256 682 http://ups.com 4111111844936880 282 23 69 SAR 47
469 Louise Shah f 079 4989 8781 079 4989 8789 Louise.C.Shah@dodgeit.com 2016-01-31 2009-08-02 2001-05-23 68 Seaford Road 10 2206 682 http://delta.com 4111116551108990 470 94 71 SAR 40
1037 Oscar Howell m 079 0500 3950 079 0500 3956 Oscar.F.Howell@pookmail.com 2016-02-14 2009-09-11 2012-08-20 46 Maidstone Road 10 436 96 http://live.com 4111117962000540 1038 96 86 BND 27
1201 Noah Middleton m 070 3851 0870 070 3851 0877 Noah.M.Middleton@trashymail.com 2016-02-01 2012-05-08 2009-07-28 78 Station Rd 8 493 977 http://badoo.com 4111115779918600 1202 25 79 BAM 61
1204 Joseph Kirby m 078 3986 6290 078 3986 6293 Joseph.M.Kirby@dodgeit.com 2016-02-18 2007-02-06 2003-11-03 1 Peachfield Road 7 3112 977 http://weather.com 4111114160574520 1205 57 77 BAM 58

5 rows × 25 columns

In [169]:

 

In [170]:

 

Out[170]:
First Name Last Name Sex Phone Fax Email Address Booking Date Departure Date Arrival Date Address1 Number of Passengers Total Cost Currency Numeric Code Company website Flight ID Number Flight Booking ID Insurance AFP Flight Name Age
1201 Noah Middleton m 070 3851 0870 070 3851 0877 Noah.M.Middleton@trashymail.com 2016-02-01 2012-05-08 2009-07-28 78 Station Rd 8 493 977 http://badoo.com 4111115779918600 1202 25 79 BAM 0
9519 Leon Harvey m 079 3516 7353 079 3516 7352 Leon.S.Harvey@dodgeit.com 2016-02-01 2001-01-18 2007-05-06 95 Southlands Road 2 1262 800 http://cbsnews.com 4111116816186750 9520 29 19 UGX 0
10748 Naomi Clayton f 079 7068 7431 079 7068 7431 Naomi.C.Clayton@trashymail.com 2016-02-01 2008-04-01 2002-06-10 88 Grenoble Road 6 2111 788 http://stylebistro.com 4111117735828380 10749 61 16 TND 0

3 rows × 25 columns

In [171]:

 

In [172]:

 

Out[172]:
AFP Age
Booking Date
2016-01-31 631 357
2016-02-01 343 0
2016-02-02 318 295
2016-02-03 356 287
2016-02-04 152 52
2016-02-05 261 305
2016-02-06 294 213
2016-02-07 373 311
2016-02-08 259 165
2016-02-09 474 429
2016-02-10 612 318
2016-02-11 312 256
2016-02-12 388 296
2016-02-13 431 433
2016-02-14 375 194
2016-02-15 195 283
2016-02-16 423 288
2016-02-17 411 258
2016-02-18 215 180
2016-02-19 166 92
2016-02-20 432 319
In [173]:

 

Out[173]:
Age
Booking Date
2016-01-31 357
2016-02-01 0
2016-02-02 295
2016-02-03 287
2016-02-04 52
2016-02-05 305
2016-02-06 213
2016-02-07 311
2016-02-08 165
2016-02-09 429
2016-02-10 318
2016-02-11 256
2016-02-12 296
2016-02-13 433
2016-02-14 194
2016-02-15 283
2016-02-16 288
2016-02-17 258
2016-02-18 180
2016-02-19 92
2016-02-20 319
In [174]:

 

Out[174]:
In [175]:

 

Out[175]:
AFP Age
Booking Date
2016-01-31 631 357
2016-02-01 343 0
2016-02-02 318 295
2016-02-03 356 287
2016-02-04 152 52
In [179]:

 

In [180]:

 

Out[180]:
AFP Age YoY %
Booking Date
2016-01-31 631 357 76.750000
2016-02-01 343 0 inf
2016-02-02 318 295 7.800000
2016-02-03 356 287 24.040000
2016-02-04 152 52 192.310000
2016-02-05 261 305 -14.430000
2016-02-06 294 213 38.030000
2016-02-07 373 311 19.940000
2016-02-08 259 165 56.970000
2016-02-09 474 429 10.490000
2016-02-10 612 318 92.450000
2016-02-11 312 256 21.880000
2016-02-12 388 296 31.080000
2016-02-13 431 433 -0.460000
2016-02-14 375 194 93.300000
2016-02-15 195 283 -31.100000
2016-02-16 423 288 46.880000
2016-02-17 411 258 59.300000
2016-02-18 215 180 19.440000
2016-02-19 166 92 80.430000
2016-02-20 432 319 35.420000
In [178]:

 

Out[178]:

 

Want more information like this?

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *