为什么我收到“无法导入名称”错误?

时间:2016-05-24 03:47:36

标签: python bokeh

我正在尝试在散景中显示时间序列图表,但我得到的错误消息是“无法导入名称'TimeSeries”。我对bokeh和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(最近一次调用最后一次)  in()       1来自yahoo_finance import Share       2个进口大熊猫为pd ----> 3.从bokeh.charts导入TimeSeries,output_file,show       4       5#从雅虎财经获取股票

ImportError:无法导入名称'TimeSeries'

1 个答案:

答案 0 :(得分:1)

您可能正在使用bokeh 0.10.x版本或更低版本。 show中的show,output_file的支持从0.11.1开始添加。将您的散景版本更新为0.12.4,您就可以全部设置。