python concat函数

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/dudu3332/article/details/102759229
test1=pd.DataFrame(np.random.randn(2,2),columns=['1','2'])
test1
test2=pd.DataFrame(np.random.randn(4,2),columns=['1','sss'])
test2
test3=pd.concat([test1,test2])
test3
test4=pd.concat([test1,test2],axis=1)
test4

结果

test3
Out[9]: 
          1         2                    sss
0 -0.683598  0.413969       NaN
1  0.304602 -1.875766       NaN
0 -0.964264       NaN  1.298050
1 -0.647045       NaN -0.555425
2  0.620427       NaN  0.813048
3  2.056769       NaN  0.026650
test4=pd.concat([test1,test2],axis=1)
test4
Out[11]: 
          1         2                     1                  sss
0 -0.683598  0.413969 -0.964264  1.298050
1  0.304602 -1.875766 -0.647045 -0.555425
2       NaN       NaN  0.620427  0.813048
3       NaN       NaN  2.056769  0.026650

默认concat不会产生重复列 推荐使用

猜你喜欢

转载自blog.csdn.net/dudu3332/article/details/102759229
今日推荐