1
次のコードは、PandasにValueErrorを発生させます。私はなぜ正常なリストを使用して正常に動作するか分からない。Pandasが列名のリストを使用しようとするとValueErrorが発生する
fileFields = [str(input("Please enter the column name for the pedigree field in
your request file.\n")),
str(input("Please enter the column name for the pedigree field
in the Tissue Library file.\n")),
str(input("Please enter the column name for the sourceID field
in the Tissue Library file.\n")),
str(input("Please enter the column name for the pedigree field in
the Gold Standard file.\n")),
str(input("Please enter the column name for the sourceID field in
the Gold Standard file.\n"))]
dfRequests = pd.read_csv(fileInputs[0], skipinitialspace=True,
usecols=fileFields[0])
dfTissueLibrary = pd.read_csv(fileInputs[1], skipinitialspace=True,
usecols=fileFields[1:2])
dfGoldStandard = pd.read_csv(fileInputs[2], skipinitialspace=True,
usecols=fileFields[3:4])
結果:
Traceback (most recent call last):
File "filepathway hidden for security", line 74, in <module>
usecols=fileFields[0])
File "filepathway hidden for security\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 529, in parser_f
return _read(filepath_or_buffer, kwds)
File "filepathway hidden for security\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 295, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "filepathway hidden for security\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 612, in __init__
self._make_engine(self.engine)
File "filepathway hidden for security\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 747, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "filepathway hidden for security\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1154, in __init__
col_indices.append(self.names.index(u))
ValueError: 'd' is not in list
パンダがfileFieldsリストの各インデックスから文字列を取得し、文字列のリストにそれらを回しているかのように私は感じています。私は、呼び出した後にインデックス付きの文字列リストを作成することでこれを解決しようとしましたが、うまくいきませんでした。助言がありますか?
'fieldField [0]'は文字列(最初に入力されたカラム)を返します。したがって、 'd'はおそらく最初のカラムの最初の文字でしょうか?もしそうなら、 'usecols = fieldFields'を設定します。 – miraculixx