我想你誤會這是怎麼回事廣場brackets-- .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
否則,你要嘗試執行的(大概)一個float按位運算。例如,如果它是一個整數,那麼它會「工作」:
>>> 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
來源
2013-03-18 16:13:21
DSM
嘗試用圓括號圍繞您的參數。 'df.ix [(df [「ptdelta」] <= 0)&(df [「ptdelta」]> 5)]'。 – bdiamante 2013-03-18 16:12:54