Update: This is a duplicate of usecols with parse_dates and names, "but this question has been answered.
I can't get this code to work for life. As soon as I output the parameter names, it works fine, but it's just plain stupid.
From a space delimited file I want:
- skip header section
- import selected columns
- specify columns
- parse two columns as date
- use processed date as index
This almost works:
import panadas as pd
columns = [4, 5, 10, 11, 15, 16, 17, 26, 28, 29]
names = ["DATE","TIME","DLAT", "DLON", "SLAT", "SLON", "SHGT", "HGT", "N", "E"]
ppp_data = pd.read_table(
filename,
delim_whitespace=True,
skiprows=8,
header=None,
usecols=columns,
names=names,
parse_dates=[[4,5]],
index_col=0,
)
print ppp_data
But here is the stack trace I get
Traceback (most recent call last):
File "plot_squat_test_pandas.py", line 30, in <module>
index_col=0,
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 400, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 205, in _read
return parser.read()
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 608, in read
ret = self._engine.read(nrows)
File "/usr/local/lib/python2.7/dist-packages/pandas/io/parsers.py", line 1028, in read
data = self._reader.read(nrows)
File "parser.pyx", line 706, in pandas.parser.TextReader.read (pandas/parser.c:6745)
File "parser.pyx", line 728, in pandas.parser.TextReader._read_low_memory (pandas/parser.c:6964)
File "parser.pyx", line 804, in pandas.parser.TextReader._read_rows (pandas/parser.c:7780)
File "parser.pyx", line 865, in pandas.parser.TextReader._convert_column_data (pandas/parser.c:8512)
File "parser.pyx", line 1105, in pandas.parser.TextReader._get_column_name (pandas/parser.c:11684)
IndexError: list index out of range
If I comment on the parameter names=namesand it works fine
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 86281 entries, 2013-10-30 00:00:00 to 2013-10-30 23:59:59
Data columns (total 8 columns):
10 86281 non-null values
11 86281 non-null values
15 86281 non-null values
16 86281 non-null values
17 86281 non-null values
26 86281 non-null values
28 86281 non-null values
29 86281 non-null values
What am I missing? Or is it a panadas problem and should I report an error?
python 2.7.3, pandas - 0.12.0. 0.13.0rc1-119-g2485e09 ( ).