パンダ19.2に問題があり、私が期待した結果が得られました。列a〜gには['yes'、 'no'、 ''、NaN]があります。これらの列のいずれかに「はい」がある場合は、行を戻したい(他の列は表示されません)。ここに私のコードです。 '.ALLは、' 私はこれは簡単で、共通のコードスニペットのように思えるパンダの論理操作
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
を得るが、私は避難所」がなければ
2134 return self._engine.get_loc(key)
2135 except KeyError:
-> 2136 return self._engine.get_loc(self._maybe_cast_indexer(key))
2137
2138 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4433)()
pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4279)()
pandas\src\hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13742)()
pandas\src\hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13696)()
KeyError: False
:
xdf2 = xdf[((xdf['a'] == 'yes').all() or
(xdf['b'] == 'yes').all() or
(xdf['c'] == 'yes').all() or
(xdf['d'] == 'yes').all() or
(xdf['e'] == 'yes').all() or
(xdf['f'] == 'yes').all() or
(xdf['g'] =='yes').all()) ]
これは私に次のエラーを与えます良い例が見つかりました。私は何が欠けていますか?
シンプルxdf2 = XDFの[(XDFの[ 'と'] == 'はい')| (xdf ['b'] == 'yes')| (xdf ['c'] == 'yes')| (xdf ['d'] == 'yes')]が動作します。 or演算子は|です。 – Vaishali