pandas.DataFrame.T() function with example in python

Spread the love

DataFrame.T() : This function  transpose index and columns.

Reflect the DataFrame over its main diagonal by writing rows as columns and vice-versa. The property T is an accessor to the method transpose().

copy : bool, default False
If True, the underlying data is copied. Otherwise (default), no copy is made if possible.

*args, **kwargs
Additional keywords have no effect but might be accepted for compatibility with numpy.

The transposed DataFrame.

import pandas as pd d = {'exp': [1, 2], 'salary': [10000, 15000]} df = pd.DataFrame(data=d) print(df) print(df.T)


exp salary
0 1 10000
1 2 15000
0 1
exp 1 2
salary 10000 15000


Leave a Reply

Your email address will not be published. Required fields are marked *