python-2.7 – .ix上的按位运算(Pandas)
发布时间:2020-12-20 11:26:06 所属栏目:Python 来源:网络整理
导读:为什么开发人员不允许在.ix上进行按位操作?好奇这是技术约束还是我忽视的逻辑问题. df.ix[df["ptdelta"]=0 df["ptdelta"]5] 追溯是: TypeError: ufunc 'bitwise_and' not supported for the input types,and the inputs could not be safely coerced to an
为什么开发人员不允许在.ix上进行按位操作?好奇这是技术约束还是我忽视的逻辑问题.
df.ix[df["ptdelta"]<=0 & df["ptdelta"]>5] 追溯是: TypeError: ufunc 'bitwise_and' not supported for the input types,and the inputs could not be safely coerced to any supported types according to the casting rule 'safe' “”” 注意:截至Pandas v0.20,.ix indexer is deprecated支持.iloc / .loc. 解决方法
我认为你误解了方括号内的内容 – .ix与它无关.如果你适当地括号,这适用:
>>> df = pd.DataFrame({"a": [-1,2,-3,4,6,-8.2]}) >>> df.ix[(df['a'] <= 0) | (df['a'] > 5)] a 0 -1.0 2 -3.0 4 6.0 5 -8.2 否则,你试图执行按位操作(可能是)浮点数.例如,如果它是一个int,那么它“工作”: >>> df['a'] <= 0 & df['a'] Traceback (most recent call last): File "<ipython-input-40-9173361ec31b>",line 1,in <module> df['a'] <= 0 & df['a'] TypeError: ufunc 'bitwise_and' not supported for the input types,and the inputs could not be safely coerced to any supported types according to the casting rule 'safe' >>> df['a'] <= 0 & df['a'].astype(int) 0 True 1 False 2 True 3 False 4 False 5 True Name: a,Dtype: bool (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |