ValueError:真值系列是不明确的

时间:2015-10-06 19:38:41

标签: pandas dataframe

我在其他帖子中搜索过此内容但未找到答案。

我有一个字典,其中key是month,value是数据帧。这是数据帧的结构(包含所有虚拟值)

    year    type            amount  #rows
0   2016    mtd_res           800      4
0   2016    mtd_unres           0      0
0   2015    mtd_res             0      0
0   2015    mtd_unres           0      0
0   2015    mtd_total_res   70000     12
0   2015    mtd_res_rem     70000     12
0   2016    mtd_exp_res     70800     16   
Name: #rows, dtype: int64

我将其存储在测试变量

test = mtd[year_month[4:]]  # mtd is the dictionary
test[test['year'] == '2015'] <-- this statement gave an error :
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

不确定我为什么会这样做。 当我尝试下面的时候,它工作正常。

>>> test[test['mtd_type']=='mtd_res']
    year    mtd_type    amount  #rows
0   2016    mtd_res       800     4  
0   2015    mtd_res         0     0

以下是test的数据类型:

>>> test.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 8 entries, 0 to 0
Data columns (total 4 columns):
year         8 non-null object
mtd_type     8 non-null object
BannerRev    8 non-null int64
#rows        8 non-null object
dtypes: int64(1), object(3)
memory usage: 320.0+ bytes

我尝试使用.any().all(),但没有任何效果。如果我在这里遗漏任何东西,请告诉我。

0 个答案:

没有答案