I want to reorganize the following mutli-row DataFrame,
1 2 3
A Apple Orange Grape
B Car Truck Plane
C House Apartment Garage
into this, single-row DataFrame.
1_A 2_A 3_A 1_B 2_B 3_B 1_C 2_C 3_C
0 Apple Orange Grape Car Truck Plane House Apartment Garage
Thank you for your help!
unstack
+ sort_index
to the rescue:
v = df.unstack().to_frame().sort_index(level=1).T
v.columns = v.columns.map('_'.join)
v
1_A 2_A 3_A 1_B 2_B 3_B 1_C 2_C 3_C
0 Apple Orange Grape Car Truck Plane House Apartment Garage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With