Python Forum
Pivoting the data does not return what I am expecting
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pivoting the data does not return what I am expecting
#1
Hi, I have a coding assignment where I am required to pivot the following data:

face_id Manipulation condition score
101 Averageness manipulated 4.428571
101 Averageness none 3.400000
101 Femininity manipulated 4.235294
101 Femininity none 3.625000
101 Masculinity manipulated 3.666667

I have tried to pivot the data to have the following columns instead: face_id, Manipulation, manipulated, none (so it looks like below):

face_id, Manipulation, manipulated, none
2, Averageness, 4.416666666666667, 4.117647058823529
2, Femininity, 3.7777777777777777, 4.130434782608695
2, Masculinity, 4.0, 4.466666666666667
2, Symmetry, 4.3076923076923075, 4.25
3, Averageness, 3.25, 2.310344827586207

However, my data ends up looking like this (or along similar lines):

condition face_id manipulated none
0 101 4.094538 3.708631
1 102 3.139303 2.855159
2 106 4.027617 3.859127
3 107 3.268579 3.208618
4 109 2.739729 2.476786

I am unsure how to get the data to pivot the way I need it to, and any guidance would be greatly appreciated! If any more information is needed, I'm happy to provide it
Reply
#2
I think I pivoted it right the first time around but one of the labels threw me off!

pivoted_data = by_faces.pivot_table(index=['face_id', 'Manipulation'], columns='condition', values='score')

pivoted_data.reset_index(inplace=True)

condition face_id Manipulation manipulated none
0 101 Averageness 4.428571 3.400000
1 101 Femininity 4.235294 3.625000
2 101 Masculinity 3.666667 4.000000
3 101 Symmetry 4.047619 3.809524
4 102 Averageness 3.695652 2.611111
Reply
#3
Please post your code (best shot, not working properly ok but explain where failures occurs).
Then you will most likely get the answers you are seeking.
Reply


Forum Jump:

User Panel Messages

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