关于Pandas中shift函数使用的问题
我的参数是按照其函数设定格式输入的,为什么会报错呢??
还请各位大佬帮忙看看感谢!
我用tushare读了某只股票的历史数据
import tushare as ts
df01 = ts.get_k_data('xxxxxx', start= '2018-01-01', end='2019-01-01')
然后想把开盘价这一列往下移两天,所以输入代码
第一行代码是为了对比两种输入的区别
print(df01.open.shift(2)[:10])
df01.open.shift(periods =2,freq='D')
下面是输出结果:
0 NaN
1 NaN
2 9.819
3 9.819
4 9.919
5 9.869
6 9.829
7 9.709
8 10.019
9 9.989
Name: open, dtype: float64
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-52-4153bcee21ea> in <module>
1 print(df01.open.shift(2)[:10])
----> 2 df01.open.shift(periods =2,freq='D')
~\Anaconda3\lib\site-packages\pandas\core\series.py in shift(self, periods, freq, axis, fill_value)
4182 def shift(self, periods=1, freq=None, axis=0, fill_value=None):
4183 return super().shift(
-> 4184 periods=periods, freq=freq, axis=axis, fill_value=fill_value
4185 )
4186
~\Anaconda3\lib\site-packages\pandas\core\generic.py in shift(self, periods, freq, axis, fill_value)
9047 )
9048 else:
-> 9049 return self.tshift(periods, freq)
9050
9051 return self._constructor(new_data).__finalize__(self)
~\Anaconda3\lib\site-packages\pandas\core\generic.py in tshift(self, periods, freq, axis)
9146 else:
9147 new_data = self._data.copy()
-> 9148 new_data.axes[block_axis] = index.shift(periods, freq)
9149
9150 return self._constructor(new_data).__finalize__(self)
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in shift(self, periods, freq)
4317 dtype='datetime64[ns]', freq='MS')
4318 """
-> 4319 raise NotImplementedError(f"Not supported for type {type(self).__name__}")
4320
4321 def argsort(self, *args, **kwargs):
NotImplementedError: Not supported for type Int64Index