我是一个python新手,试图学习在Spyder IDE上用yfinance绘制一些烛台图。我正在尝试finplot,但是你在网上看到的例子似乎根本不起作用。这招对斯派德没用吗?我错过了什么?
首先,从python控制台安装finplot和yfinance。
pip install finplot
pip install yfinance
然后在spyder IDE中复制并粘贴示例代码:
import finplot as fplt
import yfinance
df = yfinance.download('AAPL')
fplt.candlestick_ochl(df[['Open', 'Close', 'High', 'Low']])
fplt.show()
结果:
runfile('C:/Users/billgates/.spyder-py3/untitled8.py', wdir='C:/Users/billgates/.spyder-py3')
[*********************100%***********************] 1 of 1 completed
Traceback (most recent call last):
File "C:Usersbillgates.spyder-py3untitled8.py", line 4, in <module>
fplt.candlestick_ochl(df[['Open', 'Close', 'High', 'Low']])
File "c:python39libsite-packagesfinplot__init__.py", line 1304, in candlestick_ochl
_set_datasrc(ax, datasrc)
File "c:python39libsite-packagesfinplot__init__.py", line 1921, in _set_datasrc
viewbox.datasrc.addcols(datasrc)
File "c:python39libsite-packagesfinplot__init__.py", line 284, in addcols
self.df = pd.concat([df, newcols], axis=1)
File "c:python39libsite-packagespandascorereshapeconcat.py", line 298, in concat
return op.get_result()
File "c:python39libsite-packagespandascorereshapeconcat.py", line 516, in get_result
indexers[ax] = obj_labels.get_indexer(new_labels)
File "c:python39libsite-packagespandascoreindexesbase.py", line 3171, in get_indexer
raise InvalidIndexError(
InvalidIndexError: Reindexing only valid with uniquely valued Index objects
忘记创建情节。试试这个。
import finplot as fplt
import yfinance
df = yfinance.download('AAPL')
ax = fplt.create_plot()
fplt.candlestick_ochl(df[['Open', 'Close', 'High', 'Low']], ax=ax)
fplt.show()