I have the following input file:
2012,10,3,AAPL,BUY,200
2012,12,5,AAPL,SELL,200
How can I read this in into a pandas dataframe wth following columns:
index: default int range # 0
column1: datetime(2012,10,3,16) # 2012-10-03 16:00
column2: string # AAPL
column3: string # BUY
column4: integer # 200
Example:
0 2012-10-03 16:00 AAPL BUY  200
1 2012-12-05 16:00 AAPL SELL 200
Tried (pandas 0.7):
In[2]: pandas.io.parsers.read_csv("input.csv", parse_dates=[[0,1,2]], header=None)
Out[2]: 
    X.1  X.2  X.3   X.4   X.5  X.6
0  2012   10    3  AAPL   BUY  200
1  2012   12    5  AAPL  SELL  200
                Try using the read_csv() function. Ensure that your csv includes a header or pass header=None for correct parsing. parse_dates=[[0,1,2]] will facilitate the desired dattime parsing.
In [4]: pandas.io.parsers.read_csv("input.csv", parse_dates=[[0,1,2]], header=None)
Out[4]: 
              X0_X1_X2    X3    X4   X5
0  2012-10-03 00:00:00  AAPL   BUY  200
1  2012-12-05 00:00:00  AAPL  SELL  200
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With