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')