Hi,
I am having trouble figuring out how to Group Bar plot the pandas.core.series.Series below.
Not sure if this is a bug or I am doing something wrong.
If I convert the series to a dict, Bokeh makes a nice plot, but I cannot figure out how to plot the series where each origin
does not have a cyl of it’s own.
Thanks in advance…
Jim
from bokeh.charts import Bar, output_file, show
from bokeh.sampledata.autompg import autompg as df
from bokeh.plotting import output_notebook
output_notebook()
dataToPlot =df.groupby([‘cyl’,‘origin’]).mpg.mean()
print dataToPlot
type(dataToPlot)
cyl origin
3 3 20.550000
4 1 28.013043
2 28.106557
3 31.595652
5 2 27.366667
6 1 19.645205
2 20.100000
3 23.883333
8 1 14.963107
Name: mpg, dtype: float64
Out[12]:
pandas.core.series.Series
The result of your aggregation in pandas has left you with a series with a multi-level index. All of the values are there, but they are nested and printed as such.
You can prove this to yourself by doing
dataToPlot.reset_index()
If I had to guess, you want to add the call to reset_index to your chain of commands. IOW:
dataToPlot =df.groupby(by=[‘cyl’,‘origin’]).mpg.mean().reset_index()
While we’re talking about pandas and not bokeh, an alternative to line above might be (I didn’t check):
dataToPlot =df.groupby(by=[‘cyl’,‘origin’], as_index=False).mpg.mean()
Hope that helps,
-Paul
···
On Wed, Jan 18, 2017 at 7:19 AM, [email protected] wrote:
Hi,
I am having trouble figuring out how to Group Bar plot the pandas.core.series.Series below.
Not sure if this is a bug or I am doing something wrong.
If I convert the series to a dict, Bokeh makes a nice plot, but I cannot figure out how to plot the series where each origin
does not have a cyl of it’s own.
Thanks in advance…
Jim
from bokeh.charts import Bar, output_file, show
from bokeh.sampledata.autompg import autompg as df
from bokeh.plotting import output_notebook
output_notebook()
dataToPlot =df.groupby([‘cyl’,‘origin’]).mpg.mean()
print dataToPlot
type(dataToPlot)
cyl origin
3 3 20.550000
4 1 28.013043
2 28.106557
3 31.595652
5 2 27.366667
6 1 19.645205
2 20.100000
3 23.883333
8 1 14.963107
Name: mpg, dtype: float64
Out[12]:
pandas.core.series.Series
–
You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/81e6bec1-7fea-4dad-817c-d1af889ce3cf%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
Thank you, Paul!!!
It was a big help.
Matplotlib easily takes the series with a multi-level index, but Bokeh is so much prettier.
If this is the only way of making this type of plot, possibly it should be included in the examples.
Thanks again… Got to go, I have a lot of plots to make.