I have an error on line 23, it has been two hours and I still do not have the problem, this is a pie chart that shows the number of men and women in my excel file.
from math import pi
import pandas as pd
from bokeh.io import output_file, show
from bokeh.palettes import Category20c
from bokeh.plotting import figure
from bokeh.transform import cumsum
from bokeh.palettes import Spectral6
from bokeh.transform import factor_cmap
output_file("pie.html")
df = pd.read_excel(r'C:\Users\cisco\Desktop\ProyectoV\transito\homicidios-accidentes-transito-2018_1.xls')
grouped = df.groupby('Sexo')['Cantidad'].sum()
grouped * 100
print(grouped)
data = pd.Series(grouped).reset_index(name='value').rename(columns={'index':'genre'})
data['angle'] = data['value']/data['value'].sum() * 2*pi
data['color'] = Category20c[len(grouped)]
p = figure(plot_height=350, title="Género", toolbar_location=None,
tools="hover", tooltips="@Sexo: @value", x_range=(-0.5, 1.0))
p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),
line_color="white", fill_color='color', legend='Sexo', source=data)
p.axis.axis_label=None
p.axis.visible=False
p.grid.grid_line_color = None
show(p)
error
File "c:\Users\cisco\Desktop\ProyectoV\transito\genero.py", line 23, in <module>
data['color'] = Category20c[len(grouped)]
KeyError: 2