美文网首页
pandas 数据合并 concat

pandas 数据合并 concat

作者: forjie | 来源:发表于2019-12-09 11:42 被阅读0次

concat 将数据进行轴向横向合并数据,默认是按照index进行组合合并

参数介绍:

   objs:需要连接的对象集合,一般是列表或字典;

   axis:连接轴向;

   join:参数为‘outer’或‘inner’;

   join_axes=[]:指定自定义的索引;

   keys=[]:创建层次化索引;

   ignore_index=True:重建索引

例子:

left=pd.DataFrame({'key1':['foo','foo','bar','you'],
         'key2':['one','two','one','three'],
         'lval':[1,2,3,4]})

right=pd.DataFrame({'key3':['foo','foo','bar','bar'], #将上面的right的key 改了名字
         'key4':['one','one','one','two'],
         'lval':[4,5,6,7]})

df=pd.concat([left,right],axis=1)

==>
  key1   key2  lval key3 key4  lval
0  foo    one     1  foo  one     4
1  foo    two     2  foo  one     5
2  bar    one     3  bar  one     6
3  you  three     4  bar  two     7

相关文章

网友评论

      本文标题:pandas 数据合并 concat

      本文链接:https://www.haomeiwen.com/subject/njdbgctx.html