KeyError: when grouping multiple column

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)

@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].

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?

@Nelab you are not passing data in the expected format. The data for multi_line has to be a “list of lists” (or list of arrays, etc) with each sub-sequence corresponding to a different line. See the docs:

https://docs.bokeh.org/en/latest/docs/user_guide/basic/lines.html#multiple-lines

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.