创建字典 zip ,地图索引 Index.map 和 reindex 用于设置排序添加缺失的catogories,最后一个绘图 Series.plot.bar :
zip
Index.map
reindex
Series.plot.bar
s = pd.Series([6,5,5,1,1], index=[5.0,6.0,7.0,3.0,2.0]) cats = ['extremely unhappy', 'unhappy', 'partly unhappy', 'neutral', 'partly happy', 'happy', 'extremely happy'] vals = range(1, 8) d = dict(zip(vals, cats)) s.index = s.index.map(d.get) s1 = s.reindex(cats, fill_value=0) print (s1) extremely unhappy 0 unhappy 1 partly unhappy 1 neutral 0 partly happy 6 happy 5 extremely happy 5 dtype: int64 s1.plot.bar()