pd.concat合并DataFram对象

利用pandas的concat函数进行拼接DataFrame。

常用参数:

1.合并DataFrame对象列表,如[df1, df2]

2.axis,沿着哪个轴进行合并。默认是axis=0,即沿着index进行拼接。

3.igonre_index,是否重构index,默认是False,不会重构。若为True,则会重构为0,1,2....的index。

下面是对ignore_index

a = pd.DataFrame([[1, 2, 3],[4, 5, 6]], index=['index1', 'index2'], columns=['clo1', 'col2', 'col3'])
        clo1  col2  col3
index1     1     2     3
index2     4     5     6
b = pd.DataFrame([['a', 'b', 'c'],['d', 'e', 'f']], index=['index3', 'index4'], columns=['clo1', 'col2', 'col3'])
       clo1 col2 col3
index3    a    b    c
index4    d    e    f
pd.concat([a, b],ignore_incex=False) 
       clo1 col2 col3
index1    1    2    3
index2    4    5    6
index3    a    b    c
index4    d    e    f
pd.concat([a, b],ignore_index=True)
  clo1 col2 col3
0    1    2    3
1    4    5    6
2    a    b    c
3    d    e    f




猜你喜欢

转载自blog.csdn.net/im_chenxi/article/details/80398396