怎么解决报错信息,AttributeError: 'RangeIndex' object has no attribute 'to_pydatetime'?

想要用python画股票K线图,但是代码运营的时候却报错,难道不能用index.to_pydatatime吗? 求大神解决!

代码如下:

import mpl_finance as mpf
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

fig, (ax1, ax2) = plt.subplots(2,1, sharex=True)

mpf.candlestick_ohlc(ax1, zip(dates.date2num(stock_data.index.to_pydatetime()),
                         stock_data['open'], stock_data['high'],
                         stock_data['low'], stock_data['close']),
                         width=0.8, colorup='g', colordown='r')

报错如下:


An exception has occurred, use %tb to see the full traceback.

SystemExit: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: no commands supplied

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-e50d6a9afbf4> in <module>
      5 register_matplotlib_converters()
      6 
----> 7 mpf.candlestick_ohlc(ax1, zip(dates.date2num(stock_data.index.to_pydatetime()),
      8                          stock_data['open'], stock_data['high'],
      9                          stock_data['low'], stock_data['close']),

AttributeError: 'RangeIndex' object has no attribute 'to_pydatetime'
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问