import pandas as pd import numpy as np # 通过字典创建 DataFrame data = {'A':['A0', 'A1', 'A2'], 'B':['B0', 'B1', 'B2'], 'C': ['C0', 'C1', 'C2'],} df = pd.DataFrame(data) df = pd.DataFrame(data, index=['L0', 'L1', 'L2']) print(df) df3=pd.DataFrame(np.arange(16).reshape((4,4)),index=['a','b','c','d'],columns=['one','two','three','four']) df4=pd.DataFrame([6,6,6,6]).T df4.columns=df3.columns above=df3.iloc[:1] below=df3.iloc[1:] newData = above.append(df4,ignore_index=True).append(below,ignore_index=True) newData2 = pd.concat([above,df4,below],axis=0,ignore_index = True) print(newData2)
A B C L0 A0 B0 C0 L1 A1 B1 C1 L2 A2 B2 C2 one two three four 0 0 1 2 3 1 6 6 6 6 2 4 5 6 7 3 8 9 10 11 4 12 13 14 15