How to check whether data of a row is in list, inside of np.where()?
1 2 3 | 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: The truth value of a Series is ambiguous. Use a.empty,
a.bool(), a.item(), a.any() or a.all()."
最近的_下列指标是熊猫。什么是"countrycode替代检查如果是发达国家和在_?
您可以直接在熊猫过滤中使用
1 | recent_indicators_filtered = recent_indicators[recent_indicators['CountryCode'].isin(developed_countries)] |
另外,如果开发了一个Boolean列,它会显示
1 | recent_indicators['Developed'] = recent_indicators['CountryCode'].isin(developed_countries) |