Pandas索引问题

IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).

问题:索引列未对齐

原因:1、NumPy的any()用法;2、索引数据过程

关于any():

  • Python内置的any()

    • any(iterable) 如果可迭代对象iterable中的任何项为 true,则返回 True
      | 但凡内部含有__iter__方法的对象,都是可迭代对象
  • NumPy的any()

    • any(a, axis=None, out=None, keepdims=np._NoValue)
    • 用来判断(二维)数组中 某个轴向上 是否有一个元素为True
  • Pandas的any()

    • DataFrame.any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs)
    • 常和isnull()联合使用 > 判空

栗子1:

#Python内置
python = np.arange(10)
x = any(python)
print(x)  #返回True
x2 = 1
y = any(x2)   #会直接报错:'int' object is not iterable
print(y)

栗子2:

#NumPy的any:
"""
any(a, axis=None, out=None, keepdims=np._NoValue)
Test whether any array element along a given axis evaluates to True.
Returns single boolean unless axis is not None
"""
numpy = np
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值