pandas 加入不同名称的列 [英] Pandas join on columns with different names

查看:85
本文介绍了 pandas 加入不同名称的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的数据框,我想对它们执行一些sql操作.不幸的是,就像我正在使用的数据一样,拼写通常是不同的.

I have two different data frames that I want to perform some sql operations on. Unfortunately, as is the case with the data I'm working with, the spelling is often different.

请参阅以下示例,我认为语法看起来像userid属于df1,username属于df2.有人帮我吗?

See the below as an example with what I thought the syntax would look like where userid belongs to df1 and username belongs to df2. Anyone help me out?

 # not working - I assume some syntax issue?
pd.merge(df1, df2, on = [['userid'=='username', 'column1']], how = 'left')

推荐答案

名称不同时,请使用xxx_on参数代替on=:

When the names are different, use the xxx_on parameters instead of on=:

pd.merge(df1, df2, left_on=  ['userid', 'column1'],
                   right_on= ['username', 'column1'], 
                   how = 'left')

这篇关于 pandas 加入不同名称的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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