我的表:如何比较两个不同列中熊猫的值?
A Country Code1 Code2
626349 US 640AD1237 407223
702747 NaN IO1062123 407255
824316 US NaN NaN
712947 US 00220221 870262123
278147 Canada 721AC31234 109123
278144 Canada NaN 7214234321
278142 Canada 72142QW134 109123AS12
这里在上表中我需要检查的国家和代码。
我想用正确的或错误的,伪第5列:
If 'Country' == 'US' and (length(Code1) OR length(Code2) == 9):
Add values to 5th column as correct.
else:
Add values to 5th column as incorrect.
If 'Country' == 'Canada' and (length(Code1) OR length(Code2) == 10):
Add values to 5th column as correct.
else:
Add values to 5th column as incorrect.
如果没有值存在无论是在国家或代码比列信息不足。
我无法理解我该如何在熊猫中做到这一点。请帮忙。谢谢。
我试着先找到Code1和Code2的行的长度,并将其存储在不同的df
中,但之后我无法比较不同的数据集作为我需要做的。
Len1 = df.Code1.map(len)
Len2 = df.Code2.map(len)
LengthCode = pd.DataFrame({'Len_Code1': Len1,'Len_Code2': Len2})
请告诉我如何在单个数据框中尽可能地做到这一点的更好方法。
我想这
但越来越长,我就不能写了许多国家。
请问你能告诉我什么是错的,或者我你是否投了我的问题 –
@Evan Wright你能帮我在这里。 –