0
我正在尝试构建一个相当简单的脚本,它将比较CSV中的两个DataFrame并执行内部合并以删除重复项。现在我发现我的CSV的一个看起来是这样的:忽略DataFrame中的第一行CSVread
Row [0]: One column
Row [1:]: 2+ columns
现在,当我尝试通过pandas.csv_read(...)我得到以下错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pandas-0.10.0-py2.7-macosx-10.5-i386.egg/pandas/io/parsers.py", line 391, in parser_f
return _read(filepath_or_buffer, kwds)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pandas-0.10.0-py2.7-macosx-10.5-i386.egg/pandas/io/parsers.py", line 207, in _read
return parser.read()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pandas-0.10.0-py2.7-macosx-10.5-i386.egg/pandas/io/parsers.py", line 624, in read
ret = self._engine.read(nrows)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pandas-0.10.0-py2.7-macosx-10.5-i386.egg/pandas/io/parsers.py", line 945, in read
data = self._reader.read(nrows)
File "parser.pyx", line 634, in pandas._parser.TextReader.read (pandas/src/parser.c:5795)
File "parser.pyx", line 656, in pandas._parser.TextReader._read_low_memory (pandas/src/parser.c:6015)
File "parser.pyx", line 734, in pandas._parser.TextReader._read_rows (pandas/src/parser.c:6892)
File "parser.pyx", line 791, in pandas._parser.TextReader._convert_column_data (pandas/src/parser.c:7596)
File "parser.pyx", line 1015, in pandas._parser.TextReader._get_column_name (pandas/src/parser.c:10425)
我想将其导入这与第一行有关,因为当我删除它时,问题消失了。我怎样才能忽略这些错误,并用空值填充剩下的错误?
最佳, 奥利弗
它的'pandas.read_csv',你通过'skiprows = 1'跳过第一行 –
但是有没有办法自动做到这一点?也许有人有一个文件需要跳过第一个TWO行。 – oliver13
你可以用一个变量来跳过(很难说如何自动执行而不需要更多信息)... –