zoukankan      html  css  js  c++  java
  • Using If/Truth Statements with pandas¶

    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来判断是和否。

  • 相关阅读:
    正则表达式复习 (?<=) (?=)
    HTML 30分钟入门教程
    C# 多线程详解
    C# List
    C# 枚举
    C# 线程数
    C# 泛型2
    C# 泛型
    C# 结构体
    不用Google Adsense的84个赚钱方法
  • 原文地址:https://www.cnblogs.com/yaos/p/14014468.html
Copyright © 2011-2022 走看看