python - Pandas read_csv import results in error -
my csv follows (mqm q.csv):
date-time,value,grade,approval,interpolation code 31/08/2012 12:15:00,,41,1,1 31/08/2012 12:30:00,,41,1,1 31/08/2012 12:45:00,,41,1,1 31/08/2012 13:00:00,,41,1,1 31/08/2012 13:15:00,,41,1,1 31/08/2012 13:30:00,,41,1,1 31/08/2012 13:45:00,,41,1,1 31/08/2012 14:00:00,,41,1,1 31/08/2012 14:15:00,,41,1,1
the first few lines have no "value" entries start later on.
here code:
import pandas pd stringio import stringio q = pd.read_csv(stringio("""/cygdrive/c/temp/mqm q.csv"""), header=0, usecols=["date-time", "value"], parse_dates=true, dayfirst=true, index_col=0)
i next error:
traceback (most recent phone call last): file "daily.py", line 4, in <module> q = pd.read_csv(stringio("""/cygdrive/c/temp/mqm q.csv"""), header=0, usecols=["date-time", "value"], parse_dates=true, dayfirst=true, index_col=0) file "/usr/lib/python2.7/site-packages/pandas-0.14.0-py2.7-cygwin-1.7.30-x86_64.egg/pandas/io/parsers.py", line 443, in parser_f homecoming _read(filepath_or_buffer, kwds) file "/usr/lib/python2.7/site-packages/pandas-0.14.0-py2.7-cygwin-1.7.30-x86_64.egg/pandas/io/parsers.py", line 228, in _read parser = textfilereader(filepath_or_buffer, **kwds) file "/usr/lib/python2.7/site-packages/pandas-0.14.0-py2.7-cygwin-1.7.30-x86_64.egg/pandas/io/parsers.py", line 533, in __init__ self._make_engine(self.engine) file "/usr/lib/python2.7/site-packages/pandas-0.14.0-py2.7-cygwin-1.7.30-x86_64.egg/pandas/io/parsers.py", line 670, in _make_engine self._engine = cparserwrapper(self.f, **self.options) file "/usr/lib/python2.7/site-packages/pandas-0.14.0-py2.7-cygwin-1.7.30-x86_64.egg/pandas/io/parsers.py", line 1067, in __init__ col_indices.append(self.names.index(u)) valueerror: 'value' not in list
link file
this appears bug csv parser, firstly works:
df = pd.read_csv('mqm q.csv')
also works:
df = pd.read_csv('mqm q.csv', usecols=['value'])
but if want date-time
fails same error message yours.
so noticed utf-8 encoded , converted using notepad++ ansi , worked, tried utf-8 without bom , worked.
i converted utf-8 (presumably there bom) , failed same error before, don't think imaging , looks bug.
i using python 3.3, pandas 0.14 , numpy 1.8.1
to around this:
df = pd.read_csv('mqm q.csv', usecols=[0,1], parse_dates=true, dayfirst=true, index_col=0)
this set index date-time column correctly convert datetimeindex.
in [40]: df.index out[40]: <class 'pandas.tseries.index.datetimeindex'> [2012-08-31 12:15:00, ..., 2013-11-28 10:45:00] length: 43577, freq: none, timezone: none
python csv pandas
No comments:
Post a Comment