python - Weird bug when changing boolean number to classify dataframe
问题描述
I have a dataframe where I am trying to add some boolean constraints that are numbers.
hrw_hotdry=combined_hrw[(combined_hrw['June_anom']<0) & (combined_hrw['June_anom_t'])>0]
hrw_hotdry.head()
Year June_val June_anom July_val July_anom June_val_t June_anom_t July_val_t July_anom_t
0 1980 2.14 -1.40 0.99 -2.11 76.7 2.6 83.7 5.0
1 1981 2.85 -0.69 4.01 0.91 75.5 1.4 79.1 0.4
8 1988 2.08 -1.46 3.22 0.12 76.2 2.1 77.5 -1.2
10 1990 1.88 -1.66 3.16 0.06 77.3 3.2 76.7 -2.0
11 1991 3.13 -0.41 2.69 -0.41 75.1 1.0 78.4 -0.3
However, when I change the second constraint to 1 like this:
hrw_hotdry=combined_hrw[(combined_hrw['June_anom']<0) & (combined_hrw['June_anom_t'])>1]
hrw_hotdry.head()
Year June_val June_anom July_val July_anom June_val_t June_anom_t July_val_t July_anom_t
There is no output. How does this make sense?
解决方案
括号不正确:
hrw_hotdry = combined_hrw[(combined_hrw['June_anom']<0) & (combined_hrw['June_anom_t']>1.0)]
Year June_val June_anom July_val July_anom June_val_t June_anom_t July_val_t July_anom_t
0 1980 2.14 -1.40 0.99 -2.11 76.7 2.6 83.7 5.0
1 1981 2.85 -0.69 4.01 0.91 75.5 1.4 79.1 0.4
8 1988 2.08 -1.46 3.22 0.12 76.2 2.1 77.5 -1.2
10 1990 1.88 -1.66 3.16 0.06 77.3 3.2 76.7 -2.0
推荐阅读
- json-server - JSON 服务器 - 是否可以更新对象 ID?
- react-native - 具有 encodeURIComponent 值的 React-Native 获取帖子
- android - 如何正确绘制属于 ViewGroup 的 Android FloatingActionButton 实例
- phpmyadmin - 当我在 phpmyadmin 上建立连接时,他更改了我的 url 端口
- ios - MessageInputBar 在点击输入栏后消失
- javascript - Web Firestore - 将 Double 值保存到 Firebase
- dom - 如何在 vscode 扩展(电子)中访问 window.crypto?
- r - R中的重复大括号
- java - java.lang.OutOfMemoryError: Java heap space 生成pdf文档时如何解决?
- javascript - 如何在 Antd 中使用嵌套的单选按钮组?