简体   繁体   中英

How to plot a line for every group in Pandas dataframe with Bokeh

I grouped a pandas dataframe into

                 registrationtime objecthandling  counts
0  2020-01-23 06:01:57.176000+00:00         Create       2
1  2020-01-23 06:01:57.176000+00:00         Delete       1
2  2020-01-23 06:01:57.176000+00:00   buildingUUID       1
3  2020-01-23 06:04:59.723000+00:00   buildingUUID       1
4  2020-01-23 06:07:37.707000+00:00   buildingUUID       1
5  2020-01-23 06:29:48.102000+00:00         Delete       2
6  2020-01-23 06:33:03.946000+00:00   buildingUUID       2
7  2020-01-23 06:34:15.447000+00:00   buildingUUID       1
8  2020-01-23 06:38:19.964000+00:00         Create       2
9  2020-01-23 06:38:19.964000+00:00         Delete       1
10 2020-01-23 06:41:17.589000+00:00         Create       1
11 2020-01-23 06:41:17.589000+00:00         Delete       2
12 2020-01-23 06:44:51.089000+00:00         Create       2
13 2020-01-23 06:44:51.089000+00:00         Delete       2
14 2020-01-23 06:44:51.089000+00:00       geometry       1

and I want to plot lines in Bokeh where the x-axis is datetime and thereby column registrationtime , and the y-axis is counts . However, I need a separate line depending on the column objecthandling -> Create, delete, buildingUUID, geometry. In this case four different lines

My code so far

obj_handling_group = gdf.groupby(['registrationtime', 'objekthandling']).size().reset_index(name='counts')
source = ColumnDataSource(obj_handling_group)
p = figure(plot_height=350, plot_width=800, x_axis_type='datetime')
p.line(x='registrationtime', y='counts', source=source, color='navy')

Obviously this gives me one line, but how do I separate the data based on the values in column objecthandling ?

您可以像这篇文章一样将df.groupby与 Bokeh multiline结合使用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM