pandas.DataFrame.T() function with example in python
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().
Parameters:
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.
Returns:
DataFrame
The transposed DataFrame.
import pandas as pd
d = {'exp': [1, 2], 'salary': [10000, 15000]}
df = pd.DataFrame(data=d)
print(df)
print(df.T)
Output:
exp salary
0 1 10000
1 2 15000
0 1
exp 1 2
salary 10000 15000