pandas concat merge join distinction

concat is directly connected left and right, up and down

Concat can be combined horizontally by row and vertically by column

pd.concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
          keys=None, levels=None, names=None, verify_integrity=False,
          copy=True)

obs: a collection of objects with merging, which can be Series or DataFrame

axis: {0, 1...} merging direction, the default is 0, which means vertical, and 1 means horizontal;

join: {inner, outer}: merge method, the default is outer, which means union; inner means intersection;

join_axes:  According to which object index to save;

ignore _ i ndex :{False,True}, (note, here is whether to rebuild the index, the default is not to rebuild)

keys: add a key to the original dataframe, the default is none

eg:列相连,索引保持原状
>>> s1 = pd.Series(['a', 'b'])
>>> s2 = pd.Series(['c', 'd'])
>>> pd.concat([s1, s2])    
0    a
1    b
0    c
1    d
dtype: object
>>> pd.concat([s1, s2], ignore_index=True) #重新建立索引
0    a
1    b
2    c
3    d
dtype: object


>>> pd.concat([s1, s2], keys=['s1', 's2',])  #增加新的keys
s1  0    a
    1    b
s2  0    c
    1    d
dtype: object
>>> pd.concat([s1, s2], keys=['s1', 's2'],
...           names=['Series name', 'Row ID'])   #新增列名
Series name  Row ID
s1           0         a
             1         b
s2           0         c
             1         d
dtype: object


 result=pd.concat([df1, df2],axis=1)  
#横向链接(按照index连接),这里是把所有的元素联接接在一起:

 

Guess you like

Origin blog.csdn.net/yu1336199790/article/details/102951965