Skip to content Skip to sidebar Skip to footer

Swapping Axes In Pandas

What is the most efficient way to swap the axes of a Pandas Dataframe? For example, how could df1 be converted to df2 below? In [2]: import pandas as pd In [3]: df1 = pd.DataFrame

Solution 1:

Take a look at transpose

In [4]: df1.T
Out[4]: 
     0  1  2  3
one  1  2  3  4 
two  4  3  2  1

Post a Comment for "Swapping Axes In Pandas"