2
votes

I am trying to display a time series chart in bokeh but the error message I get reads "cannot import name 'TimeSeries ". I am very new to bokeh, and python, so any and all help will be greatly appreciated.

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)

yields this error:

ImportError Traceback (most recent call last) in () 1 from yahoo_finance import Share 2 import pandas as pd ----> 3 from bokeh.charts import TimeSeries, output_file, show 4 5 # Getting stocks from Yahoo Finance

ImportError: cannot import name 'TimeSeries'

1
Can you show full traceback from console? - Artem Selivanov
Have you been able to import any part of the module bokeh? I would guess this is a module installation issue. - Jenner Felton
You either have a version of Bokeh installed that is too old to run this example, or you have an installation problem. - bigreddot

1 Answers

1
votes

Probably you are using bokeh 0.10.x version or below. The support for show, output_file in bokeh was added from 0.11.1 onward. Update your bokeh version to 0.12.4 and you'll be all set.