天天看點

Pandas中DataFrame資料合并concat

df1=DataFrame(np.random.randn(3,4),columns=[‘a’,‘b’,‘c’,‘d’])

df2=DataFrame(np.random.randn(2,3),columns=[‘b’,‘d’,‘a’])

pd.concat([df1,df2])

a         b         c         d  
           

0 -0.848557 -1.163877 -0.306148 -1.163944

1 1.358759 1.159369 -0.532110 2.183934

2 0.532117 0.788350 0.703752 -2.620643

0 -0.316156 -0.707832 NaN -0.416589

1 0.406830 1.345932 NaN -1.874817

pd.concat([df1,df2],ignore_index=True)

a         b         c         d  
           

0 -0.848557 -1.163877 -0.306148 -1.163944

1 1.358759 1.159369 -0.532110 2.183934

2 0.532117 0.788350 0.703752 -2.620643

3 -0.316156 -0.707832 NaN -0.416589

4 0.406830 1.345932 NaN -1.874817

原文:https://blog.csdn.net/gdkyxy2013/article/details/80785361

繼續閱讀