我想从晨星导入数据并生成烛台图。你知道吗
import numpy as np
import pandas as pd
import pandas_datareader.data as web
import mpl_finance as mpf
import matplotlib.pyplot as plt
AAPL = web.DataReader('AAPL', 'morningstar', start = '1/1/2000',end = '5/29/2018')
fig, ax = plt.subplots(figsize = (8,5))
fig.subplots_adjust(bottom=0.2)
mpf.candlestick_ohlc(ax, AAPL, width = 0.6, colorup = 'b', colordown = 'r', alpha = 0.75)
ax.xaxis_date()
ax.autoscale_view()
ax.xaxis.grid(True, 'major')
ax.grid(True)
我得到一个错误:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
非常感谢您的帮助
您可以尝试将数据转换为浮点:
AAPL.astype(float)
,看起来里面可能有字符串而不是数字。你知道吗另外,我认为你必须使用序数日期和
mpl_finance candlestick_ohlc
:然后在你的
candlestick_ohlc
中使用它,而不是AAPL
。你知道吗相关问题 更多 >
编程相关推荐