swap rows and columns pandas 1

swap rows and columns pandas

df_tr = df.transpose()
print(df_tr)
#            0    1        2
# name   Alice  Bob  Charlie
# age       24   42       18
# state     NY   CA       CA
# point     64   92       70

Here is what the above code is Doing:
1. We created a DataFrame from a dictionary.
2. We used the transpose() method to swap the rows and columns.
3. We printed the result.

Similar Posts