1、concat竖着拼接(默认的竖着,axis=0)

话不多说,直接看例子:

import pandas as pd

df1=pd.DataFrame([10,12,13])
df2=pd.DataFrame([22,33,44,55])
df3=pd.DataFrame([90,94])
df1
0
010
112
213
df2
0
022
133
244
355
df3
0
090
194
res= pd.concat([df1,df2,df3])
res
0
010
112
213
022
133
244
355
090
194

如果要生成新索引,忽略原来索引怎么办?
默认有个参数ignore_index= False,将其值改为True
:

res2= pd.concat([df1,df2,df3], ignore_index=True)
res2
0
010
112
213
322
433
544
655
790
894

2、concat横着拼接

用参数axis= 1,看例子:

res_heng= pd.concat([df1,df2,df3], axis=1)
res_heng
000
010.02290.0
112.03394.0
213.044NaN
3NaN55NaN
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐