How to switch column rows in pandas framework

I have the following framework:

                                0       1
0                 enrichment_site   value
1                    last_updated   value
2                     image_names   value
3                 shipping_weight   value
4                        ean_gtin   value
5                        stockqty   value
6                      height__mm   value
7                    availability   value
8                             rrp   value
9                             sku   value
10                     price_band   value
11                           item   value

I tried with a pivot table

test.pivot(index=index, columns='0', values='1')

but I get the following error:

KeyError: '1'

any alternative pivot table for this?

+4
source share
2 answers

You can use df = df.Tto transfer the data frame. This switches the data frame so that the rows become columns.

You can also use pd.DataFrame.transpose.

+29
source

When using pd.DataFrame.transpose (as suggested by Jamie Bull / coldspeed), be sure to write

pd.DataFrame.transpose()

... without brackets, this did not work for me.

0
source

All Articles