Examples
Square DataFrame with homogeneous dtype:
import numpy as np
import pandas as pd
d1 = {'c1': [2, 3], 'c2': [4, 5]}
df1 = pd.DataFrame(data=d1)
df1
df1_transposed = df1.T # or df1.transpose()
df1_transposed
When the dtype is homogeneous in the original DataFrame, we get a transposed
DataFrame with the same dtype:
df1.dtypes
df1_transposed.dtypes
Non-square DataFrame with mixed dtypes:
d2 = {'name': ['Jimmy', 'Monty'],
'score': [10.5, 9],
'employed': [False, True],
'kids': [0, 0]}
df2 = pd.DataFrame(data=d2)
df2
df2_transposed = df2.T # or df2.transpose()
df2_transposed
When the DataFrame has mixed dtypes, we get a transposed DataFrame
with the object dtype:
df2.dtypes
df2_transposed.dtypes