Looking to get the list of dates from my Quandl object but I am unsure what is the mistake I am making. I am sure it is exceptionally easy but I cannot seem to solve it.
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 14 22:54:55 2014
@author:
"""
import Quandl;
import pandas as pd;
key_="myKey123";
mydata = Quandl.get("BCHARTS/BITSTAMPUSD", authtoken=key_);
The request works, and I see:
>>> mydata.head()
Open High Low Close Volume (BTC) Volume (Currency) \
Date
2011-09-13 5.80 6.00 5.65 5.97 58.371382 346.097389
2011-09-14 5.58 5.72 5.52 5.53 61.145984 341.854813
2011-09-15 5.12 5.24 5.00 5.13 80.140795 408.259002
2011-09-16 4.82 4.87 4.80 4.85 39.914007 193.763147
2011-09-17 4.87 4.87 4.87 4.87 0.300000 1.461000
Weighted Price
Date
2011-09-13 5.929231
2011-09-14 5.590798
2011-09-15 5.094272
2011-09-16 4.854515
2011-09-17 4.870000
[5 rows x 7 columns]
I am trying to get the list of dates by doing the following:
>>> mydata["Date"]
Gives me the following error:
self._check_have(item)
File "/Library/Python/2.7/site-packages/pandas-0.13.0-py2.7-macosx-10.9-intel.egg/pandas/core/internals.py", line 3072, in _check_have
raise KeyError('no item named %s' % com.pprint_thing(item))
KeyError: u'no item named Date'
How do I extract just the dates?
Thanks
Date is the index on your DataFrame - you can access it with mydata.index
If you want to make 'Date' a column, you can reset the index, as follows:
In [35]: mydata = mydata.reset_index()
In [36]: mydata['Date']
Out[36]:
0 2011-09-13
1 2011-09-14
2 2011-09-15
3 2011-09-16
4 2011-09-17
Name: Date, dtype: datetime64[ns]