標籤:

Pandas學習-6concat合併

import pandas as pdimport 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])# print(df1)# print(df2)# print(df3)# res = pd.concat([df1,df2,df3],axis=0)# print(res)##############join[outer,inner]# 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],join=inner,ignore_index=True)# print(res)######################join_axes# 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])# res = pd.concat([df1,df2],axis=1,join_axes=[df1.index])# print(res)#########################appenddf1 = 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))*1,columns=[a,b,c,d])print(df1)print(df2)res = df1.append(df2,ignore_index=True)res1 = df1.append([df2,df3])# print(res)print(res1)s1 = pd.Series([1,2,3,4],index=[a,b,c,d])res2 = df1.append(s1,ignore_index=True)print(res2)

推薦閱讀:

pandas dataFrame 繪圖函數—plot學習筆記
如何與pandas愉快地玩耍(二)
Pandas學習-8pandas plot圖表
如何與pandas愉快地玩耍(一)

TAG:pandas包 |