散景错误 FactorRange 必须为轴指定一个唯一的分类因子列表:找到重复因子:'M. Laxmikanth'

bokeh error FactorRange must specify a unique list of categorical factors for an axis: duplicate factors found: 'M. Laxmikanth'

我的数据是这样的

data.iloc[:,1]

41                         Barack Obama
95                 Muthuvenkatachalam S
16                        M. Laxmikanth
21                         R S Aggarwal
32                        R.S. Aggarwal
58                  MTG Editorial Board
7                           James Clear
54                         Ramesh Singh
70                      Nitin Singhania
88                        M. Laxmikanth
81    Think Tank of Kiran Institute of…
99                               Solimo
2                    Wonder House Books
39                         Navdeep Kaur
33                          Jeff Kinney
Name: Author, dtype: object

我们可以看到16和88是一样的,也就是M. Laxmikant

p = figure(x_range=data.iloc[:,1], plot_width=800, plot_height=550, title="Authors Highest Priced Book", toolbar_location=None, tools="")
p.vbar(x=data.iloc[:,1], top=data.iloc[:,4], width=0.9)
p.xgrid.grid_line_color = None
p.y_range.start = 0
p.xaxis.major_label_orientation = math.pi/2
show(p)

我已经导入了所有必要的库。这给了我错误

ERROR:bokeh.core.validation.check:E-1019 (DUPLICATE_FACTORS): FactorRange must specify a unique list of categorical factors for an axis: duplicate factors found: 'M. Laxmikanth'

我该如何解决?

您需要将 data.iloc[:,1] 缩减为一组唯一的值,然后按照您希望它们出现在轴上的顺序对它们进行排序。在 Python 中唯一化序列的一种常见方法是将其传递给 set.