RustyShackleford
RustyShackleford

Reputation: 3677

How to pivot dataframe without having to set index?

I have a df that looks like this:

col1     value
test1     abc
test2     def

How do I flip the dataframe without having to add an index using pivot_table?

New df should look like this (without the existing column names ideally):

test1    test2
abc      def

edit: df.T

gives me:
       abc    def
test1  1      0 
test2  0      1

Upvotes: 1

Views: 47

Answers (1)

Mayank Porwal
Mayank Porwal

Reputation: 34086

Just take the DataFrame.transpose:

In [2576]: df
Out[2576]: 
    col1 value
0  test1   abc
1  test2   def

In [2577]: df.T
Out[2577]: 
           0      1
col1   test1  test2
value    abc    def

Upvotes: 2

Related Questions