python + pandas
Posted: Mon Nov 19, 2012 6:43 pm
I started using pandas (the most recent version) about 1 hour ago, so I am still trying to figure out how to do the most basic things. Is there a fast way to parse a timestamp of the format HH:MM:SS.MS using pandas.to_datetime()?
Here is a sample of a few lines of the data file I am working with:
2012/11/01,17:53:01.621,1.22010,1000000,1.22040,1000000
2012/11/01,17:54:59.812,1.22009,500000,1.22040,1000000
2012/11/01,17:54:59.833,1.22009,500000,1.22043,500000
2012/11/01,17:55:00.468,1.22008,500000,1.22043,500000
2012/11/01,17:55:03.853,1.22009,500000,1.22060,500000
2012/11/01,17:57:29.565,1.22010,1000000,1.22060,500000
2012/11/01,17:57:30.236,1.22010,1000000,1.22085,500000
columnNames=['sessionDate','sessionTime','bidPrice','bidSize','askPrice','askSize']
Basically, I want to load a file with multiple sessions and downsample to hourly OHLC for each session. The sessionDate column is not a calendar day, but rather a session date. So, for example quotes between 17:05 and 23:59 on Sunday 2012/11/11 are found under the date Monday 2012/11/12 and so on. Is there an easy way to do this using pandas? There doesn't seem to be any functionality for defining a session, but I am probably missing something.
I can load the file via
data=pd.read_csv(fileName,names=columnNames)
and extract the data via
sessionDate=data['sessionDate']
sessionTime=data['sessionTime']
bidPrice=data['bidPrice']
bidSize=data['bidSize']
askPrice=data['askPrice']
askSize=data['askSize']
spread=askPrice-bidPrice
but I haven't been able figure out how to parse the timestamp, create a time series object and downsample yet.
Any suggestions?
Here is a sample of a few lines of the data file I am working with:
2012/11/01,17:53:01.621,1.22010,1000000,1.22040,1000000
2012/11/01,17:54:59.812,1.22009,500000,1.22040,1000000
2012/11/01,17:54:59.833,1.22009,500000,1.22043,500000
2012/11/01,17:55:00.468,1.22008,500000,1.22043,500000
2012/11/01,17:55:03.853,1.22009,500000,1.22060,500000
2012/11/01,17:57:29.565,1.22010,1000000,1.22060,500000
2012/11/01,17:57:30.236,1.22010,1000000,1.22085,500000
columnNames=['sessionDate','sessionTime','bidPrice','bidSize','askPrice','askSize']
Basically, I want to load a file with multiple sessions and downsample to hourly OHLC for each session. The sessionDate column is not a calendar day, but rather a session date. So, for example quotes between 17:05 and 23:59 on Sunday 2012/11/11 are found under the date Monday 2012/11/12 and so on. Is there an easy way to do this using pandas? There doesn't seem to be any functionality for defining a session, but I am probably missing something.
I can load the file via
data=pd.read_csv(fileName,names=columnNames)
and extract the data via
sessionDate=data['sessionDate']
sessionTime=data['sessionTime']
bidPrice=data['bidPrice']
bidSize=data['bidSize']
askPrice=data['askPrice']
askSize=data['askSize']
spread=askPrice-bidPrice
but I haven't been able figure out how to parse the timestamp, create a time series object and downsample yet.
Any suggestions?