![]() |
Pivoting the data does not return what I am expecting - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Pivoting the data does not return what I am expecting (/thread-41791.html) |
Pivoting the data does not return what I am expecting - loulou1997 - Mar-19-2024 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 RE: Pivoting the data does not return what I am expecting - loulou1997 - Mar-19-2024 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 RE: Pivoting the data does not return what I am expecting - Larz60+ - Mar-21-2024 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. |