☰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

KeyError: when grouping multiple column

Community Supportbokeh
Nelab
Nelab

I have csv data and trying to plot graph rtt overtime for each IP address in the data.
Here is the code to plot the graphs. There is a “KeyError” being raised when trying to plot the data. Any recommendations?

data.csv 
time,ip,rtt,jitter
2023-02-17 12:01:00,192.168.1.1,25,100
2023-02-17 12:02:00,192.168.1.1,27,110
2023-02-17 12:03:00,192.168.1.1,28,110
2023-02-17 12:04:00,192.168.1.2,25,100
2023-02-17 12:05:00,192.168.1.2,28,110
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
from bokeh.palettes import Category10
from bokeh.transform import factor_cmap
import pandas as pd


data = pd.read_csv('data.csv', parse_dates=['time'])

factors = data['ip'].unique().tolist()

source = ColumnDataSource(data)

p = figure(x_axis_type='datetime', plot_width=800, plot_height=400, title='RTT over time by IP address')

colors = factor_cmap('ip', palette=Category10[2], factors=factors)

p.multi_line(xs='time', ys='rtt', source=source, line_width=2, line_color=colors, legend_field='ip')

p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'RTT (ms)'
p.legend.title = 'IP Address'

show(p)
⌁   Link to post
Bryan
Bryan

@Nelab Please always post entire stack traces. I could have answered this immediately if that information had been provided.

There is no Category10[2]. The smallest Category10 palette that exists has three colors, i.e. Category10[3].

⌁   Link to post
Nelab
Nelab

Thanks Bryan. That is correct. Key Error was on line 16
—> 16 colors = factor_cmap(‘ip’, palette=Category10[2], factors=factors)

Changed to Category10[3] and no errors. But bokeh plot showing blank data for rtt over time by IP. Anything missing in the bokeh Bokeh to plot a line chart with multiple lines?

⌁   Link to post

End of archived discussion · Replies are disabled