如何并排合并两个数据框? [英] How to merge two dataframes side-by-side?

查看:229
本文介绍了如何并排合并两个数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以方便地并排合并两个数据帧?

is there a way to conveniently merge two data frames side by side?

两个数据帧都有30行,它们具有不同的列数,例如df1有20列,df2有40列.

both two data frames have 30 rows, they have different number of columns, say, df1 has 20 columns and df2 has 40 columns.

如何轻松获得30行60列的新数据框?

how can i easily get a new data frame of 30 rows and 60 columns?

df3 = pd.someSpecialMergeFunct(df1, df2)

或者也许在append中有一些特殊参数

or maybe there is some special parameter in append

df3 = pd.append(df1, df2, left_index=False, right_index=false, how='left')

ps:如果可能的话,我希望复制的列名可以自动解析.

ps: if possible, i hope the replicated column names could be resolved automatically.

谢谢!

推荐答案

您可以为此使用concat函数(axis=1被串联为列):

You can use the concat function for this (axis=1 is to concatenate as columns):

pd.concat([df1, df2], axis=1)

有关合并/串联的信息,请参见pandas文档: http://pandas.pydata .org/pandas-docs/stable/merging.html

See the pandas docs on merging/concatenating: http://pandas.pydata.org/pandas-docs/stable/merging.html

这篇关于如何并排合并两个数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆