【发布时间】:2021-06-04 17:37:04
【问题描述】:
我是一个 python 新手,试图学习在 Spyder IDE 上使用 yfinance 绘制一些烛台图。我正在尝试 finplot,但是您在网上看到的示例似乎根本不起作用。这不应该与 Spyder 一起使用吗?我错过了什么?
首先,从 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:\Users\billgates\.spyder-py3\untitled8.py", line 4, in <module>
fplt.candlestick_ochl(df[['Open', 'Close', 'High', 'Low']])
File "c:\python39\lib\site-packages\finplot\__init__.py", line 1304, in candlestick_ochl
_set_datasrc(ax, datasrc)
File "c:\python39\lib\site-packages\finplot\__init__.py", line 1921, in _set_datasrc
viewbox.datasrc.addcols(datasrc)
File "c:\python39\lib\site-packages\finplot\__init__.py", line 284, in addcols
self.df = pd.concat([df, newcols], axis=1)
File "c:\python39\lib\site-packages\pandas\core\reshape\concat.py", line 298, in concat
return op.get_result()
File "c:\python39\lib\site-packages\pandas\core\reshape\concat.py", line 516, in get_result
indexers[ax] = obj_labels.get_indexer(new_labels)
File "c:\python39\lib\site-packages\pandas\core\indexes\base.py", line 3171, in get_indexer
raise InvalidIndexError(
InvalidIndexError: Reindexing only valid with uniquely valued Index objects
【问题讨论】:
-
在 AAPL 之后似乎有一些空间
-
没有多余的空间。我也用其他符号尝试过,它们都给出了相同的结果。