###前提・実現したいこと
Python3.6 Pandasを用いて、ファイル”XXX.csv”を読み込み、column”AA”において"BBB"を含むindexを抽出し、”XXX2.csv”として出力したいと考えています。
###発生している問題・エラーメッセージ
C:\Users\mymt_akck\Anaconda3\python.exe C:/Users/mymt_akck/PycharmProjects/untitled/training2.py Traceback (most recent call last): File "C:\Users\mymt_akck\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2442, in get_loc return self._engine.get_loc(key) File "pandas_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\hashtable_class_helper.pxi", line 1210, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas_libs\hashtable_class_helper.pxi", line 1218, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'AA' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/mymt_akck/PycharmProjects/untitled/training2.py", line 5, in df1 = df1[df1["AA"] == "BBB"] File "C:\Users\mymt_akck\Anaconda3\lib\site-packages\pandas\core\frame.py", line 1964, in getitem return self._getitem_column(key) File "C:\Users\mymt_akck\Anaconda3\lib\site-packages\pandas\core\frame.py", line 1971, in _getitem_column return self._get_item_cache(key) File "C:\Users\mymt_akck\Anaconda3\lib\site-packages\pandas\core\generic.py", line 1645, in _get_item_cache values = self._data.get(item) File "C:\Users\mymt_akck\Anaconda3\lib\site-packages\pandas\core\internals.py", line 3590, in get loc = self.items.get_loc(item) File "C:\Users\mymt_akck\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2444, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\hashtable_class_helper.pxi", line 1210, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas_libs\hashtable_class_helper.pxi", line 1218, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'AA' Process finished with exit code 1 `
###該当のソースコード
import pandas as pd df1=pd.read_csv('XXX.csv','low_memory=False',engine='python',encoding='utf-8') df1 = df1[df1["AA"] == "BBB"] df1.to_csv("XXX2.csv")
###試したこと
###補足情報(言語/FW/ツール等のバージョンなど
Python3.6 プログラミングは初心者です。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/29 13:13