pandas follows the numpy convention of raising an error when you try to convert something to a bool. This happens in a if or when using the boolean operations, and, or, or not. It is not clear what the result of

>>>if pd.Series([False, True, False]):
...

should be. Should it be True because it’s not zero-length? False because there are False values? It is unclear, so instead, pandas raises a ValueError:

>>> if pd.Series([False, True, False]):
print("I was true")
Traceback
...
ValueError: The truth value of an array is ambiguous. Use a.empty, a.any() or a.all().

这种情况下的布尔运算存在歧义,python不知道该以pd.Series是否为空为判断是和否,还是以pd.Series中是否有False来判断是和否。

Using If/Truth Statements with pandas的更多相关文章

  1. [WiX]Component Rules 101

    原文:http://robmensching.com/blog/posts/2003/10/18/component-rules-101 I've been debating with myself ...

  2. python pandas进行条件筛选时出现ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().”

    在使用pandas进行条件筛选时,使用了如下的代码: fzd_index=data[(data['实际辐照度']<mi)or(data['实际辐照度']>ma)].index 原本以为,并 ...

  3. 学习笔记之pandas

    Python Data Analysis Library — pandas: Python Data Analysis Library https://pandas.pydata.org/ panda ...

  4. 10分钟学习pandas

    10 Minutes to pandas This is a short introduction to pandas, geared mainly for new users. You can se ...

  5. 【译】10分钟学会Pandas

    十分钟学会Pandas 这是关于Pandas的简短介绍主要面向新用户.你可以参考Cookbook了解更复杂的使用方法 习惯上,我们这样导入: In [1]: import pandas as pd I ...

  6. pandas小记:pandas数据输入输出

    http://blog.csdn.net/pipisorry/article/details/52208727 数据输入输出 数据pickling pandas数据pickling比保存和读取csv文 ...

  7. numpy&pandas补充常用示例

    Numpy [数组切片] In [115]: a = np.arange(12).reshape((3,4)) In [116]: a Out[116]: array([[ 0, 1, 2, 3], ...

  8. 十分钟搞定 pandas

    原文:http://pandas.pydata.org/pandas-docs/stable/10min.html 译者:ChaoSimple 校对:飞龙 官方网站上<10 Minutes to ...

  9. 10分钟上手python pandas

    目录 Environment 开始 对象创建 查看数据 选择 直接选择 按标签选择 按位置选择 布尔索引 设置 缺失数据 操作 统计 应用(apply) 直方图化(Histogramming) 字符串 ...

随机推荐

  1. 微信小程序接口封装

    看到个不错的总结,如下 https://blog.csdn.net/weixin_42270487/article/details/84868443 https://kuangpf.com/mpvue ...

  2. 多行文本溢出隐藏处理,兼容ie,火狐

    问题 多行文本溢出隐藏,webkit内核浏览器如谷歌支持如下写法: overflow: hidden; text-overflow: ellipsis; display: -webkit-box; - ...

  3. android7.0对于SharedPreferences设置模式的限制

    错误信息: 03-28 10:16:12.701   830   932 E AndroidRuntime: FATAL EXCEPTION: Thread-903-28 10:16:12.701   ...

  4. Selenium WebDriver高级应用

    WebDriver高级应用 public class Demo4 { WebDriver driver; // @BeforeMethod:在每个测试方法开始运行前执行 @BeforeMethod p ...

  5. C# DataTable删除行Delete与Remove的问题

    DataTable删除行使用Delete后,只是该行被标记为deleted,但是还存在,用Rows.Count来获取行数时,还是删除之前的行数,需要使用datatable.AcceptChanges( ...

  6. php Function ereg() is deprecated的解决方法

    PHP 5.3 ereg() 无法正常使用,提示“Function ereg() is deprecated Error”.问题根源是php中有两种正则表示方法,一个是posix,一个是perl,ph ...

  7. HTML --JS 选择框

    <html> <head> <title>选择框</title> <script language="JavaScript"& ...

  8. 牛顿迭代法理论推导及python代码实现

    公式不便于在这里编辑,所以在word中编辑好了,截图过来. 用python+牛顿迭代法   求 y =(x-2)**3的解 import numpy as np import matplotlib.p ...

  9. Linux系统的镜像文件iso下载地址

    CentOS-6.1-x86_64-bin-DVD1.iso 官方网址:http://archive.kernel.org/centos-vault/6.1/isos/x86_64/ 下载链接地址:h ...

  10. Codeforces 1156E Special Segments of Permutation(单调栈)

    可以用单调栈直接维护出ai所能覆盖到的最大的左右范围是什么,然后我们可以用这个范围暴力的去查询这个区间的是否有满足的点对,一个小坑点,要对左右区间的大小进行判断,只需要去枚举距离i最近的一段区间去枚举 ...