我有两个excel文件。两者都包含关于相同数据对象的信息。数据对象由对象编号(列ON
)标识,该编号的类型为str
example:
Table 1 Table 2
ON colA colB colToUpdate ON colImportant
1.2.3 abc 123 1.2.3 inf
2.9.6 ert 987 1.2.3 mat
3.5.0 nms 021 2.9.6 mat
2.9.6 tr
2.9.6 ch
3.5.0 tr
及
myValues={inf, ch}
Task:
我需要检查表2中的colImportant
值之一是否在我的myValues
中,并且该数据对象(具有相同对象编号的行)需要在df1
中的colToUpdate
中获取值“Ok”
expectation:
new Table 1
ON colA colB colToUpdate
1.2.3 abc 123 Ok
2.9.6 ert 987 Ok
3.5.0 nms 021 NaN
我考虑将两者保存在一个单独的数据帧中(表1 inddf1
和表2 indf2
),并在更新df1
中的下一列时始终在df2
中搜索相同的对象号。但这将始终搜索整个df2
(大约有30000个数据对象,这意味着df1
中有30000行。在df2
中,有75000行,因为一个数据对象可以与另一个值一起多次存储在colImportant
中,如上所示)
另一个想法是在{df1
中的行时,我必须检查分割的值。
完成后,我可以删除tempCol
。
应该是这样的:
Table 1
ON colA colB colToUpdate tempCol
1.2.3 abc 123 inf,mat
2.9.6 ert 987 mat,tr,ch
3.5.0 nms 021 inf
以下是我的方法:
输出:
不完美,但我想你可以解决
相关问题 更多 >
编程相关推荐