【发布时间】:2018-08-13 10:21:24
【问题描述】:
下面是我的代码
years_list = set()
for i in range(0,indicators_csv.shape[0]) :
if (indicators_csv['CountryCode'].str.contains('USA')) :
years_list.append(indicator_csv.iloc[i].Year)
这里的 indicator_csv 是一个 csv 文件,其列为“CountryCode” 运行时出现以下错误
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
在 if 行。我也试过了
if (indicators_csv['CountryCode'] == ('USA'))
但得到同样的错误。
我用谷歌搜索了一些与数字或和或相关的答案,但没有找到类似的答案。
【问题讨论】:
-
indicators_csv 是熊猫系列吗?
-
@saravanakumarv 没有它的熊猫数据框
-
抛出错误是因为您试图在需要单个布尔值的 IF 子句中使用一系列布尔值。
标签: python-3.x pandas data-science