私は29列のデータテーブルを読み込み、1つのインデックス列に合計30個を追加しました。Python pandas.core.indexing.IndexingError:Unalignable booleanシリーズキーを提供
Data = pd.read_excel(os.path.join(BaseDir, 'test.xlsx'))
Data.reset_index(inplace=True)
次に、列名に「ref」または「Ref」が含まれている列のみを含むようにデータをサブセット化したいと考えました。私は別のスタックポストからのコードの下になった:
col_keep = Data.ix[:, pd.Series(Data.columns.values).str.contains('ref', case=False)]
しかし、私はこのエラーを取得しておいてください。
print(len(Data.columns.values))
30
print(pd.Series(Data.columns.values).str.contains('ref', case=False))
0 False
1 False
2 False
3 False
4 False
5 False
6 False
7 False
8 False
9 False
10 False
11 False
12 False
13 False
14 False
15 False
16 False
17 False
18 False
19 False
20 False
21 False
22 False
23 False
24 True
25 True
26 True
27 True
28 False
29 False
dtype: bool
Traceback (most recent call last):
File "C:/Users/lala.py", line 26, in <module>
col_keep = FedexData.ix[:, pd.Series(FedexData.columns.values).str.contains('ref', case=False)]
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 84, in __getitem__
return self._getitem_tuple(key)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 816, in _getitem_tuple
retval = getattr(retval, self.name)._getitem_axis(key, axis=i)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1014, in _getitem_axis
return self._getitem_iterable(key, axis=axis)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1041, in _getitem_iterable
key = check_bool_indexer(labels, key)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1817, in check_bool_indexer
raise IndexingError('Unalignable boolean Series key provided')
pandas.core.indexing.IndexingError: Unalignable boolean Series key provided
だから、ブール値は正しいですが、なぜそれが機能していませんか?なぜエラーがポップアップし続けるのですか?
助けてください/ヒントありがとうございます!そんなにありがとう。
ありがとうございます!それはうまくいった:) – alwaysaskingquestions