想要用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'