import numpy as np
import pandas as pd
# concatenating
df1 = pd.DataFrame(np.ones((3, 4))*0, columns= ['a', 'b', 'c', 'd'])
df2 = pd.DataFrame(np.ones((3, 4))*1, columns= ['a', 'b', 'c', 'd'])
df3 = pd.DataFrame(np.ones((3, 4))*2, columns= ['a', 'b', 'c', 'd'])
print(df1)
print(df2)
print(df3)
# axis=0 按上下合并, axis=1 按左右合并
res1 = pd.concat([df1, df2, df3], axis = 0, ignore_index=True)
print(res1)
# join, ['inner', 'outer']
df4 = pd.DataFrame(np.ones((3, 4))*0, columns= ['a', 'b', 'c', 'd'], index= [1, 2, 3])
df5 = pd.DataFrame(np.ones((3, 4))*1, columns= ['b', 'c', 'd', 'e'], index= [2, 3, 4])
print(df4)
print(df5)
# 合并两者都有的部分
res2 = pd.concat([df4, df5], join= 'inner', ignore_index=True)
print(res2)
# append
df6 = pd.DataFrame(np.ones((3, 4))*0, columns= ['a', 'b', 'c', 'd'])
df7 = pd.DataFrame(np.ones((3, 4))*1, columns= ['a', 'b', 'c', 'd'])
df8 = pd.DataFrame(np.ones((3, 4))*1, columns= [ 'b', 'c', 'd', 'e'], index= [2, 3, 4])
res3 = df6.append(df7, ignore_index=True)
#s1 = pd.Series([1, 2, 3, 4], index= ['a', 'b', 'c', 'd'])
#res3 = df1.append(s1, ignore_index= True)
print(res3)