【发布时间】:2017-01-23 05:16:01
【问题描述】:
我正在尝试在散景中显示时间序列图表,但我收到的错误消息显示为“无法导入名称 'TimeSeries”。我对散景和 python 非常陌生,因此将不胜感激任何和所有帮助。
from yahoo_finance import Share
import pandas as pd
from bokeh.charts import TimeSeries, output_file, show
# Getting stocks from Yahoo Finance
yahoo = Share('YHOO')
google = Share('GOOGL')
# User selects stocks
stock = input("Enter stock name: ")
choice = Share(stock)
yahoo.refresh()
choice.refresh()
# gets stock data for a desired Stock
yahooData = choice.get_historical('2016-05-01', '2016-05-23')
# all dates are stored here
date = []
# all stock prices are stored here
data = []
# sanity check to see if the thing works
for i in range(10):
date.append(yahooData[i]['Date'])
data.append(yahooData[i]['Adj_Close'])
print(date[i], data[i], sep=' ')
# turns the two lists into a data frame
stock_data = pd.DataFrame({'Dates': date , 'Prices' : data})
stock_data
# Where things go to s**t
p = TimeSeries(stock_data, index = 'Dates', legend = 'True', title = "Stock Chart", ylabel = 'Prices')
output_file("Stock_chart.html")
show(p)
产生此错误:
ImportError Traceback(最近一次调用最后一次) 在 () 1 来自 yahoo_finance 进口 分享 2 将熊猫作为 pd 导入 ----> 3 from bokeh.charts import TimeSeries, output_file, show 4 5 # 从雅虎财经获取股票
ImportError: 无法导入名称“TimeSeries”
【问题讨论】:
-
你能从控制台显示完整的回溯吗?
-
您是否能够导入模块散景的任何部分?我猜这是模块安装问题。
-
您安装的 Bokeh 版本太旧而无法运行此示例,或者您有安装问题。