Python Forum
Should it be pivot or unstack for this sample
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Should it be pivot or unstack for this sample
#1
I am very new to python . should I be using the pivot or unstack to get the expected output. Any sample code is appreciated.
Sample Input is
==================
year c1 c2 time date entered week rank
2000 AA SSS1 4:22 2000-02-26 wk1 87
2000 BB SSS2 3:15 2000-09-02 wk1 91
2000 CC SSS3 3:53 2000-04-08 wk1 81
2000 CC SSS4 4:24 2000-10-21 wk1 76
2000 DD SSS5 3:35 2000-04-15 wk1 57
2000 AA SSS1 4:22 2000-02-26 wk2 82
2000 BB SSS2 3:15 2000-09-02 wk2 87
2000 CC SSS3 3:53 2000-04-08 wk2 70
2000 CC SSS4 4:24 2000-10-21 wk2 76
2000 DD SSS5 3:35 2000-04-15 wk2 34
2000 AA SSS1 4:22 2000-02-26 wk3 72
2000 BB SSS2 3:15 2000-09-02 wk3 92
2000 CC SSS3 3:53 2000-04-08 wk3 68
2000 CC SSS4 4:24 2000-10-21 wk3 72
2000 DD SSS5 3:35 2000-04-15 wk3 25

Expecting ouput :
++++++++++++++++++++
year c1 c2 time date entered wk1 wk2 wk3
2000 AA SSS1 4:22 2000-02-26 87 82 72
2000 BB SSS2 3:15 2000-09-02 91 87 92
2000 CC SSS3 3:53 2000-04-08 81 70 68
2000 CC SSS4 4:24 2000-10-21 76 76 72
2000 DD SSS5 3:35 2000-04-15 57 34 25

molten7 is above mentioned input
tidy7 = molten7.pivot(index=('c1','c2','time','date entered'),columns='week',values='rank')
give me the following error
KeyError: ('c1', 'c2', 'time', 'date entered') ....
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need Help! Pandas EXCEL PIVOT psb3958 1 916 Nov-13-2022, 10:37 PM
Last Post: deanhystad
  group by create pivot table python dawid294 1 1,258 Jun-22-2022, 06:13 PM
Last Post: Larz60+
  SQL Pivot EAV Quentin 2 2,782 Dec-03-2019, 11:52 PM
Last Post: Quentin
  How to pivot a dat UGuntupalli 0 1,855 Oct-17-2019, 11:13 PM
Last Post: UGuntupalli
  pivot error shyamdba 1 2,419 Feb-02-2018, 11:12 PM
Last Post: klllmmm

Forum Jump:

User Panel Messages

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