☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

groupby as ColumnDataSource

Community Support
Jonathan_Bennett
Jonathan_Bennett

When you set a groupby as a ColumnDataSource, how do you update the ColumnDataSource.data?

A Pandas DataFrame object

source = ColumnDataSource(data=df)

to update:

source.data = dict(df)

A Pandas GroupBy object

group = df.groupby((‘colA’, ‘ColB’))

source = ColumnDataSource(data=group)

to update:

???

When I try

source.data = dict(group)

I get: “error handling message Message ‘PATCH-DOC’ (revision 1): TypeError(“attribute of type ‘list’ is not callable”,)”

Do I need to manipulate the group object when I pass the updated version back to the ColumnDataSource?

Thanks,

Jonathan

⌁   Link to post
Bryan
Bryan

Hi,

CDS can automatically initialize from a Pandas GroupBy, but there's not a *public* API for updating. You should be able to do this, for now:

  source.data = source._data_from_groupy(group)

However, PLEASE NOTE: Code that uses this now WILL have to change in the near future. As we approach 1.0 the entire API surface is being re-visited, and appropriately decorated to maintain rigorously under test. This method, being useful for people to use, will have to become "internal" or "public" instead of pure private (i.e. it will have to lose the underscore, at minimum).

Thanks,

Bryan

···

On Sep 29, 2017, at 13:43, Jonathan Bennett <jonathan@konoanalytics.com> wrote:

When you set a groupby as a ColumnDataSource, how do you update the ColumnDataSource.data?

https://bokeh.pydata.org/en/latest/docs/reference/models/sources.html

A Pandas DataFrame object
source = ColumnDataSource(data=df)

to update:
source.data = dict(df)

A Pandas GroupBy object
group = df.groupby(('colA', 'ColB'))
source = ColumnDataSource(data=group)

to update:
???

When I try
source.data = dict(group)
I get: "error handling message Message 'PATCH-DOC' (revision 1): TypeError("attribute of type 'list' is not callable",)"

Do I need to manipulate the group object when I pass the updated version back to the ColumnDataSource?

Thanks,
Jonathan

--
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 bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e0592116-280d-4f13-879d-2ab74167ef06%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post

End of archived discussion · Replies are disabled