我收到错误时,我对数据框中的单个元素进行比较,但我不明白为什么。熊猫布尔comparisson对数据框
我有时间序列数据的数据帧DF为一些客户,一些空值在其中:
df.head()
8143511 8145987 8145997 8146001 8146235 8147611 \
2012-07-01 00:00:00 NaN NaN NaN NaN NaN NaN
2012-07-01 00:30:00 0.089 NaN 0.281 0.126 0.190 0.500
2012-07-01 01:00:00 0.090 NaN 0.323 0.141 0.135 0.453
2012-07-01 01:30:00 0.061 NaN 0.278 0.097 0.093 0.424
2012-07-01 02:00:00 0.052 NaN 0.278 0.158 0.170 0.462
在我的剧本,行 if pd.isnull(df[[customer_ID]].loc[ts]):
产生一个错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
但是,如果我在脚本行上放置了一个断点,并且脚本停止时,我将它输入到控制台中:
pd.isnull(df[[customer_ID]].loc[ts])
输出为:
8143511 True
Name: 2012-07-01 00:00:00, dtype: bool
如果我允许脚本从该点继续,则立刻产生错误。
如果可以计算布尔表达式并且其值为True
,为什么它会在if表达式中生成一个错误?这对我来说没有意义。
检查答案:http://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty -a-bool-a-item-a-any-o – Rohanil
好的,谢谢。因此,如果我使用 pd.isnull(df_gen [[customer_ID]]。loc [ts] .item()),那么该布尔值被评估为OK,但我不明白为什么原始文件不起作用。 – doctorer
由于原始返回''对象,它不是布尔值。 –
Rohanil