我想每天将5天添加到原始DataFrame中
首先,我导入了必要的组件
import pandas as pd
import datetime as dt
pd.core.common.is_list_like = pd.api.types.is_list_like
from pandas_datareader import data
import pandas_datareader.data as web
from datetime import datetime
然后我创建了我的DataFrame
company = "MSFT"
start = datetime(2015, 2, 9)
end = dt.datetime.now()
stocks = web.DataReader(company, "iex",start,end)
现在我想在DataFrame开始之前添加5天。所以我用了DateOffset
stocks.index
stocks.index + pd.DateOffset(days = 5)
现在正在向我显示此错误
TypeError跟踪(最近的呼叫 最后)在() ----> 1个stocks.index + pd.DateOffset(天= 5)
/anaconda2/lib/python2.7/site-packages/pandas/core/indexes/base.pyc在 添加(自己,其他)2684 2685 def 添加(自己,其他): -> 2686 return Index(np.array(self)+ other)2687 2688 def radd (self,other):
pandas / _libs / tslibs / offsets.pyx在 pandas._libs.tslibs.offsets.BaseOffset。 radd ()
/anaconda2/lib/python2.7/site-packages/pandas/tseries/offsets.pyc在 添加(自己,其他) 346返回其他+自我 347尝试: -> 348返回self.apply(其他) 349除ApplyTypeError外: 350 return NotImplemented
/anaconda2/lib/python2.7/site-packages/pandas/tseries/offsets.pyc在 包装器(自己,其他) 75其他= other.tz_localize(无) 76 ---> 77 result = func(self,other) 78 79如果self._adjust_dst:
/anaconda2/lib/python2.7/site-packages/pandas/tseries/offsets.pyc在 申请(自己,其他) 212,如果self.n> 0: 213 for i in range(self.n): -> 214其他=其他+自我。 215其他: 216 for i in range(-self.n):
TypeError:强制转换为Unicode:需要字符串或缓冲区,relativedelta 找到