뉴비에욤

파이썬 Jupyter Notebook 실전 입문 최신 버전 반영 코드 pg 300 본문

Machine Learning/Visualize

파이썬 Jupyter Notebook 실전 입문 최신 버전 반영 코드 pg 300

초보에욤 2019. 3. 20. 15:59

pg 300

DataFrame 이용하기

리스트/그림 6.4.5



import os

import pandas as pd

from bokeh.palettes import Spectral11

from bokeh.plotting import output_notebook, figure, show


output_notebook()


base_url = 'https://raw.githubusercontent.com/practical-jupyter/sample-data/master/anime/'

anime_stock_returns_csv = os.path.join(base_url, 'anime_stock_returns.csv')

df = pd.read_csv(anime_stock_returns_csv, index_col=0, parse_dates=['Date'])

numlines = len(df.columns)


data = {'xs': [df.index.values] * numlines,

        'ys': [df[name].values for name in df ],

        'colors' : Spectral11[0:numlines],

         'labels': [name for name in df]}

source = ColumnDataSource(data)


p = figure(plot_width=700, plot_height=400, x_axis_type='datetime')


p.multi_line(source=source, xs='xs', ys='ys', 

             legend = 'labels',

             line_width = 3, 

             line_color = 'colors')

show(p)




Comments