与groupby()和Bokeh Figure()都困难

时间:2019-04-08 11:25:19

标签: pandas-groupby bokeh

我不知道确切的位置,但我相信我还没有将数据分配给图形,请帮忙将这些数据从边缘拖回图形中吗?

from bokeh.plotting import figure, output_notebook, show
import numpy as np
import pandas as pd
from bokeh.models import ColumnDataSource
from bokeh.colors import RGB
from bokeh.sampledata.autompg2 import autompg2 as data


data = pd.read_csv('auto-mpg2.csv', thousands=',', index_col='class')
output_notebook()
print(data.dtypes)
dataHeads = data.head()

group =  data[100:150].groupby('class')
group1 = data[100:150].groupby('cty')
source = ColumnDataSource(group, group1)
#dataHeads
#yA = dataU.loc['a4']
#dataU.loc['malibu'].cty
p = figure(plot_height=500, plot_width=1200, x_range=group, title='City 
MPG vs Class MPG',
      x_axis_label='Class', y_axis_label='MPG')
p.vbar(x=index, top=index, width=0.9, color ='#35B778', source=source)

show(p)

1 个答案:

答案 0 :(得分:0)

Do you mean something like this?

from bokeh.plotting import figure, output_notebook, show
import numpy as np
import pandas as pd
from bokeh.models import ColumnDataSource
from bokeh.colors import RGB
from bokeh.sampledata.autompg2 import autompg2 as data

df = pd.DataFrame(data)
source = ColumnDataSource(df)
group = data[100:150].groupby('class')

p = figure(plot_height = 500, plot_width = 1200, x_range = group, title = 'City MPG vs Class MPG',
      x_axis_label = 'Class', y_axis_label = 'MPG')
p.vbar(x = 'class', top = 'cty', width = 0.9, color = '#35B778', source = source)

show(p)

enter image description here