Skip to content Skip to sidebar Skip to footer

How To Make Types In The Rows Of Pandas Dataframe To Become The Column Header With Result As Row Type?

I have a df structured in following setting and would like to change it so that the types found in the column type are the the row readers with the original result as the row the n

Solution 1:

Try pivot_table with rename_axis:

>>> df.pivot_table('result', ['id', 'name'], 'type', aggfunc=''.join).reset_index().rename_axis(columns=None)
  id        name    1  2    3
0  A       Apple    X  X    X
1  B      Banana    Y  Y  NaN
2  C  Cantaloupe  NaN  Z    Z
>>> 

Post a Comment for "How To Make Types In The Rows Of Pandas Dataframe To Become The Column Header With Result As Row Type?"