python - 我如何计算“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()。
那么我该如何处理呢?
感谢您的帮助!
解决方案
推荐阅读
- jmeter - 使用 PEM 文件进行 jmeter 身份验证
- c# - 如何从 Windows 窗体浏览器 C# 中删除 cookie?
- eclipse - 如何让eclipse不折叠子文件夹?
- xml - JAXBContext 和 @XmlRootElement 导致错误
- python - 清除任务气流
- java - Java 6 中具有复杂数据结构的对象克隆/拆分
- c++ - 当我使用 osgDB::readNodeFile 时,如何跳过加载错误的 osgb 文件?
- c# - 为什么使用 CryptoStream 而不是 TransformBlock?
- primeng - 带有分页器附加页面的 PrimeNG p-table 忽略“行”
- heroku-cli - 在 ubuntu 18.04 上安装最新版本后不推荐使用 heroku cli