首页 > 解决方案 > 我如何计算“DataFrame”中大于或小于特定值的值的长度?

问题描述

这是示例:

# Suppose you have this dictionary
di = {1:0.2 , 4:0.6 , 3:0.98 , 2:0.98}

# and Now create a DataFrame from the dictionary
di = pd.DataFrame.from_dict(di,orient='index')

# Now i want to count valuse in the DataFrame that are more than 0.8 or less than 0.4
## Here is what i wrote
len(   di[di[0]>0.8 or di[0]<0.4]   )

但我得到了这个错误:

ValueError:Series 的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。

那么我该如何处理呢?
感谢您的帮助!

标签: pythonpandasdataframedictionary

解决方案


推荐阅读