python - pandas Series bool与运算

 平凡天使心619 发布于 2022-10-27 20:35
In[101]: x.head()
Out[101]: 

0    1.559343
1    1.103526
2    0.791218
3    0.946919
4    1.120411
Name: Beta, dtype: float64

In[102]: x[~np.isnan(x) and x > x.mean() + 3 * x.std()] = x.mean() + 3 * x.std()
Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "", line 1, in 
    x[~np.isnan(x) and x > x.mean() + 3 * x.std()] = x.mean() + 3 * x.std()
  File "C:\Anaconda3\lib\site-packages\pandas\core\generic.py", line 892, in __nonzero__
    .format(self.__class__.__name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

In[103]: ~np.isnan(x)
Out[103]: 

0        True
1        True
2        True
3        True
4        True
5        True
6        True
7        True
8        True
9        True
10       True
11       True

Series不能对两个bool值进行and运算吗,bool值也是pandas.Series的序列,有什么简单办法?

1 个回答
  • and 换为 &

    x[~np.isnan(x) & x > x.mean() + 3 * x.std()]

    2022-10-29 04:17 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有