Pandas 将列从一个数据框中复制到另一个具有不同名称的数据框中 [英] Pandas Copy columns from one data frame to another with different name

查看:56
本文介绍了Pandas 将列从一个数据框中复制到另一个具有不同名称的数据框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将列从一个 DataFrame A 复制到另一个 DataFrame B.AB 中的列名不匹配.

I have to copy columns from one DataFrame A to another DataFrame B. The column names in A and B do not match.

最好的方法是什么?有几个这样的列.我是否需要为每一列编写像 B["SO"] = A["Sales Order"]

What is the best way to do it? There are several columns like this. Do I need to write for each column like B["SO"] = A["Sales Order"] etc.

推荐答案

我会使用 pd.concat

combiend_df = pd.concat([df1, df2[['column_a', 'column_b']]], axis=1)

还使您能够连接不同大小的日期框、外连接等.

also gives you the power to concat different size dateframes , outer join etc.

这篇关于Pandas 将列从一个数据框中复制到另一个具有不同名称的数据框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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