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. UE4开发PSVR游戏的常见问题

    Failed to connect to file server at xxx.xxx.xxx.xxx. RETRYING in 5s解决办法:PS4 Devkit 中 Settings->De ...

  2. 无题II

    无题II Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. python中将12345转换为54321

    #将12345转换为54321 a = 12345789 ret = 0 #当a不为零的时候,循环条件为true,执行语句块 while a : #对a求余数,第一次循环则把5求出来 last = a ...

  4. (转)cat > file << EOF 的用法

    转:https://www.cnblogs.com/chenjingchao/p/6259572.html cat> 文件名<<eof 用来创建文件在这之后输入任何东西 都是在 文件 ...

  5. centos R包 tidyverse安装

    tidyverse安装失败,install.packages('tidyverse') 错误原因大概是其中有个依赖包xml2安装不上,解决办法是yum install libxml2-devel,这样 ...

  6. python web自动化测试框架搭建(功能&接口)——功能测试模块

    功能测试使用selenium,模块有: 1.futil: 公共方法,如元素高亮显示 # coding=utf-8 """高亮显示元素""" ...

  7. Linux 文件和目录的权限设置 - umask(默认权限),chmod(改变权限)

    1. chmod 改变已有目录或文件的权限 chmod 设置已有目录或文件的权限.可以为指定范围的用户添加或删除权限. 权限范围的表示法如下: u:User,即文件或目录的拥有者: g:Group,即 ...

  8. 模拟赛T5 : domino ——深搜+剪枝+位运算优化

    这道题涉及的知识点有点多... 所以还是比较有意思的. domino 描述 迈克生日那天收到一张 N*N 的表格(1 ≤ N ≤ 2000),每个格子里有一个非 负整数(整数范围 0~1000),迈克 ...

  9. ssh公私钥免密登陆

    简介ssh Secure Shell(简写SSH) 为一项建立在应用层和传输层基础上的安全协议,专门为远程登录会话和其他网络服务提供安全性的协议. SSH安全机制分为两种,一种是基于口令的安全认证,一 ...

  10. ES6 find 和 filter 的区别

    ES6 find 和 filter 的区别 : 遇到个功能是要分类就想说在前端过滤,不要从查数据库的时候过滤了.然后就想说除了filter还有啥好用的 发现有个find,测试一番之后发现 const ...