ll1735 2016-08-30 07:48 采纳率: 0%
浏览 4600

pandas Series bool与运算

 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 "<ipython-input-102-4a0654e0fc5c>", line 1, in <module>
    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的序列,有什么简单办法,必须转换用a.all()这种函数吗

  • 写回答

1条回答

  • dabocaiqq 2017-02-08 20:36
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?