Need help with loading historical data

So I am new to quantconnect and python and have been going through some samples to load historical data. I am running into issue while reading the time column from dataframe. Here is my code

df = qb.History(5)
print df

print df["close"] # This works

print df["time] # This does not work

Based on the output from printing the df it seems 'symbol' and 'time' column are not on the first line but second while the rest of the columns close, high, low, open, volume are on first line. How can I resolve this issue?

Update Backtest

Hi Gurdeep,

There are a few time series like open, close, high, low associated with each symbol. Therefore, we use multi-index in history data request. When you use qb.History(5), the return will be a multi-indexed python dataframe. The first level of the index is the symbol. The second level is the timestamp. While the column of the dataframe is only one level (open, high, low and so on). 

You could use the symbol to get a dataframe

df = qb.History(5)
df1 = df.loc["AAPL"] # dataframe indexed by timestamp
df1.index # print the time index


Very helpful. However I am still unable to access data

df = qb.History(5, Resolution.Daily)
ibmDF = df.loc["IBM"] # Works
ibmIndex = ibmDF.index.values #Works

ibmIndex #Works

ibmIndex[0] #Works

ibmDF[ibmIndex[0]] # Does not work

What am I missing.



This worked. Thanks again!


Update Backtest


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


This discussion is closed