import pandas as pd
import numpy as np
# generate original (test) dataframe
df = pd.DataFrame({f'col_{i+1}': np.random.randint(0, 100, 20) for i in range(10)})
# transpose the first two rows into a new dataframe
df1 = df.iloc[:2, :].T.reset_index(drop=True)
# rename columns as needed
df1.rename(columns={0: 'A', 1: 'B'}, inplace=True)
1条答案
按热度按时间kmbjn2e31#
您需要做的只是转置 Dataframe (前两行):