我有一个主df
,它有一列我想用第二个df1
的值更新。你知道吗
对我来说,棘手的部分是,我需要对每个df的2个公共列进行匹配,以知道要更新哪个值。你知道吗
举个例子:
df col1 col2 col3
1 1A Z4 4
2 1B Z5 2
3 1C Z6 7
4 1D Z7 1
5 1E Z12 9
df1 col1 col2 col3
1 1G Z9 1
2 1B Z5 2
3 1C Z6 3
4 1D Z7 4
5 1E Z8 5
输出:
df col1 col2 col3
1 1A Z4 4 (no match, no update)
2 1B Z5 2 (match, updated)
3 1C Z6 3 (match, updated)
4 1D Z7 4 (match, updated)
5 1E Z12 9 (not matched on both, no update)
谢谢你的帮助。你知道吗
可以将
set_index
与update
一起使用通过使用
numpy.where
以及我从@jezrael的解中发现的三元运算符。你知道吗相关问题 更多 >
编程相关推荐