Hello,
I am cleaning some data for a subsequent merge. The data has different index types(Timestamp and datetime.date) with dates that match. Here is a picture with a description of each type:
And how they are taken and transformed into a dictionary to rename the index of the DataFrame.
######### Initialize: This is the data that I am using
self.spy = self.AddEquity("SPY")
self.wti = self.AddEquity('WTI')
self.tb_rates = self.AddData(USTreasuryYieldCurveRate, "USTYCR") # Treasury bills rate
# qb.Download('https://fred.stlouisfed.org/graph/fredgraph.csv?id=PSAVERT') # Same data as txt
self.ps = self.AddData(Quandl,"FRED/PSAVE") # Personal savings, given monthly by the FRED
######### This is called from the OnData Method
history = self.History([self.spy.Symbol, self.wti.Symbol, self.tb_rates.Symbol], self.data_acum*2, Resolution.Daily)
history = history.append(self.History(self.tb_rates.Symbol, timedelta(740), Resolution.Daily),sort=False)
nw_ind = np.array(pd.to_datetime(pd.Series(history.index.get_level_values(1)),utc=True).dt.date)
old_ind = np.array(history.index.get_level_values(1))
history.rename(index = dict(zip(old_ind,nw_ind)), inplace=True)
I get the following error at the last line: TypeError: zip argument #1 must support iteration
How can I solve this problem? Thanks in advance.
Louis Szeto
Hi Andres
To rename a particular level of index in a pd.DataFrame, the fastest way would be df.index.set_levels().
Best
Louis
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.
Andres tello
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!