标签:frame style numpy 表示 das 方向 and spl splay
axis合并方向
import pandas as pd import pickle import numpy as np 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‘]) #0表示竖项合并 1表示横项合并 ingnore_index重置序列index index变为0 1 2 3 4 5 6 7 8 res = pd.concat([df1, df2, df3], axis=0, ignore_index=True) print(res)
输出
a b c d 0 0.0 0.0 0.0 0.0 1 0.0 0.0 0.0 0.0 2 0.0 0.0 0.0 0.0 3 1.0 1.0 1.0 1.0 4 1.0 1.0 1.0 1.0 5 1.0 1.0 1.0 1.0 6 2.0 2.0 2.0 2.0 7 2.0 2.0 2.0 2.0 8 2.0 2.0 2.0 2.0
join合并方式
import pandas as pd import pickle import numpy as np df1 = pd.DataFrame(np.ones((3,4))*0, columns=[‘a‘,‘b‘,‘c‘,‘d‘], index=[1,2,3]) df2 = pd.DataFrame(np.ones((3,4))*1, columns=[‘b‘,‘c‘,‘d‘, ‘e‘], index=[2,3,4]) print(df1) print(df2) res=pd.concat([df1,df2],axis=1,join=‘outer‘)#行往外进行合并,并集 print(res) res=pd.concat([df1,df2],axis=1,join=‘inner‘)#行相同的进行合并,合并都有的行,交集 print(res) res=pd.concat([df1,df2],axis=1,join_axes=[df1.index])#以df1的序列进行合并 df2中没有的序列NaN值填充 print(res)
输出
a b c d 1 0.0 0.0 0.0 0.0 2 0.0 0.0 0.0 0.0 3 0.0 0.0 0.0 0.0 b c d e 2 1.0 1.0 1.0 1.0 3 1.0 1.0 1.0 1.0 4 1.0 1.0 1.0 1.0 a b c d b c d e 1 0.0 0.0 0.0 0.0 NaN NaN NaN NaN 2 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 3 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 4 NaN NaN NaN NaN 1.0 1.0 1.0 1.0 a b c d b c d e 2 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 3 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 a b c d b c d e 1 0.0 0.0 0.0 0.0 NaN NaN NaN NaN 2 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 3 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0
append添加数据
标签:frame style numpy 表示 das 方向 and spl splay
原文地址:https://www.cnblogs.com/sea-stream/p/10319874.html