developed_countries = ["NOR","AUS","CHE","DEU","DNK","SGP","NLD","IRL","ISL","CAN","USA","NZL","SWE","LIE","GBR"]
recent_indicators['Developed'] = np.where(recent_indicators['CountryCode'] in developed_countries, 1, 0)
“ValueError:系列的真值是不明确的 . 使用a.empty,a.bool(),a.item(),a.any()或a.all() . ”
recent_indicators 是pandas DataFrame . 有什么可以替代检查在develop_countries中是否提到'CountryCode'?
1 回答
您可以直接在pandas过滤中使用
.isin()
-此外,您可以提出一个布尔列,如果开发了
True
-