Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Can't make bar chart after groupby. #12
Thank you very much for making great package. I'm really into it. I'd like to report the bug with the latest version
I think it happens because groupy method makes categorical index.
Hi, I'm glad you enjoy using my package and thanks for reporting me your bug.
The reason why it fails is the following, when I look at your result DataFrame, it looks like:
So, the values of the index are tuples (or better Pandas Intervals). The bar method then basically takes the index (or what should be used for the x-axis) and converts it to a string to show it on the x-axis. (so basically each bar has a central point). However, it also stores the original object in the plot (for using it as a DataSource). Since Bokeh translates everything into a finalo html, it tries to serialize everything to JSON, but he doesn't know how to do this for a Pandas interval.
There are now two possible solutions for your problem. Either you make:
import numpy as np import pandas as pd import pandas_bokeh pandas_bokeh.output_notebook() x = np.arange(0, 100, 0.1) df = pd.DataFrame(x) result = df.groupby(pd.cut(df, np.arange(0, 100, 10))).sum() result.index = result.index.astype(str) result.plot_bokeh.bar()
Alternatively, I would propose that you do:
import numpy as np import pandas as pd import pandas_bokeh pandas_bokeh.output_notebook() x = np.arange(0, 100, 0.1) df = pd.DataFrame(x) result = df.groupby(pd.cut(df, np.arange(0, 100, 10))).sum() result.index = np.arange(5, 90, 10) result.plot_bokeh.bar()
I hope that I could help you. If you have further questions, please answer to this post. If you issue is solved, please also write me such that I can close it.