1
以下代码会导致Pandas引发ValueError。我不知道为什么使用正常列表工作正常。当尝试使用列名称列表时,熊猫引发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