I am trying to read similar to below CSV file to pandas.DataFrame:
2011 1 10 AAPL Buy 1500
2011 1 13 AAPL Sell 1500
2011 1 13 IBM Buy 4000
2011 1 26 GOOG Buy 1000
Data doesn't have column headers. When I read that file I also want to parse first 3 columns to a 'date' column. So the following is what I tried:
import pandas
pandas.read_csv(fileName,
header = None,
names = ('Date', 'Symbol', 'Side', 'Quantity'),
parse_dates = {'Date' : [0, 1, 2]})
That raises:
NotImplementedError: file structure not yet supported
I tried:
pandas.read_csv(fileName,
header = None,
names = ('Year', 'Month', 'Day', 'Symbol', 'Side', 'Quantity'),
parse_dates = {'Date' : ['Year', 'Month', 'Day']})
and neither did that work and threw the same exception.
So finally I accomplished reading that file by:
orders = pandas.read_csv(fileName,
header = None,
parse_dates = {'Date' : [0, 1, 2]})
orders.rename(columns = {3: 'Symbol', 4 : 'Side', 5: 'Quantity'})
Is there a way to make the first call to work by passing column names to names? Why that exception is raised? Similar problem was reported in Pandas file structure not supported error but I couldn't see any solution other than the same workaround.
I am using pandas 0.18.1 which is the latest version to my knowledge.