我有两个数据帧:
测向:
index some_variable identifier1 identifier2
1 x AB2 AB3
2 x BB2 BB3
3 x CB2 CB3
4 y DB2 DB3
5 y EB2 EB3
dfa公司:
index some_variable identifier1 identifier2 identifier3
1 x AB5 AB3 AB3
2 x BB5 BB2 AB2
3 x CB5 CB2 AB5
4 y DB5 DB3 AB3
5 y EB5 EB3 AB3
如果df['identifier1']
的元素在dfa['identifier2']
中,则用dfa['identifier3']
替换该索引df['identifier2']
,如果某个变量等于'x'
。所以条件是:
[(df['identifier1'].isin(dfa['identifier2'])&(df[some_variable]=='x')]
我想要:
index some_variable identifier1 identifier2
1 x AB2 AB3
2 x BB2 AB2
3 x CB2 AB5
4 y DB2 DB3
5 y EB2 EB3
我可以设置条件,但不知道如何获得输出。你知道吗
如下所示(尽管可能有更简单的方法)
我想这就是你想要做的:
相关问题 更多 >
编程相关推荐