Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
get_pricing() date?

I'm experimenting with the research notebooks and am currently working with the get_pricing() function. If I do this:

day_pricing = get_pricing("MSFT", start_date='2002-10-15', end_date='2016-12-07')  
print day_pricing  

It outputs:
open_price high low close_price \
2002-10-15 00:00:00+00:00 25.633 26.1750 25.3250 26.153
2002-10-16 00:00:00+00:00 25.195 25.6300 25.1400 25.205
2002-10-17 00:00:00+00:00 26.140 26.2500 25.0300 25.385
2002-10-18 00:00:00+00:00 26.300 26.6000 25.5700 26.575

If I loop over the day_pricing with:

for day in day_pricing:  
  print day  

It outputs the columns: open_price, high, low, close_price, volume, price. But it doesn't contain the date of the price.

I can loop over the number or rows and output a single price or the volume, but how do I get that date value at a specific row?

Something like: day_pricing['date'][1] = 2002-10-16 00:00:00+00:00

Steve

2 responses

Are you just trying to view the data? Forget prints and loops. Python objects generally know how to display themselves. The prices get returned in a pandas dataframe object which has a nice display rendering. Just type:

day_pricing  

The date is the index of the dataframe and not actually one of the columns. In order to reference an index value you need to do something like:

day_pricing.index.values[3]

This would return the 4th index (remember python uses zero based indexing).
See attached notebook.

Perfection. Thank you Dan. That's exactly what I was looking for.