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?
Jing Wu
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
qb.AddEquity("AAPL") qb.AddEquity("IBM") df = qb.History(5) df1 = df.loc["AAPL"] # dataframe indexed by timestamp df1.index # print the time index
Gurdeep S
Very helpful. However I am still unable to access data
df = qb.History(5, Resolution.Daily)
df.index
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.
Gurdeep S
df.loc["IBM"].loc["2018-03-09"]
This worked. Thanks again!
Gurdeep S
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!