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
你可以用一個變量來跳過(很難說如何自動執行而不需要更多信息)... –