Rya*_*yan -1 python pandas seaborn
我有一个 pandas 数据框df,并尝试使用 seaborn 库来创建小提琴图。
rank sentiment category
0 1 0.657413 m
1 2 0.895769 m
2 3 -0.435457 m
3 4 -0.717959 m
4 5 0.869688 m
Run Code Online (Sandbox Code Playgroud)
这是seaborn线路:
sns.violinplot(x="rank", y="senitment", hue="category", data=df)
Run Code Online (Sandbox Code Playgroud)
我不断收到这个ValueError
ValueError: Could not interpret input 'senitment'
Run Code Online (Sandbox Code Playgroud)
全程追溯
violinplot 中的 /Users/jrs/anaconda/lib/python3.5/site-packages/seaborn/categorical.py(x,y,色调,数据,顺序,hue_order,bw,剪切,比例,scale_hue,网格大小,宽度,内部、分割、方向、线宽、颜色、调色板、饱和度、ax、**kwargs)2299 bw、剪切、缩放、scale_hue、网格大小、2300 宽度、内部、分割、方向、线宽、-> 2301 颜色、调色板、饱和度)第2302章 2303、如果ax是无:
/Users/jrs/anaconda/lib/python3.5/site-packages/seaborn/categorical.py in __init__(self, x, y, hue, data, order, hue_order, bw, cut, scale, scale_hue, gridsize, width, inner, split, orient, linewidth, color, palette, saturation)
535 color, palette, saturation):
536
--> 537 self.establish_variables(x, y, hue, data, orient, order, hue_order)
538 self.establish_colors(color, palette, saturation)
539 self.estimate_densities(bw, cut, scale, scale_hue, gridsize)
/Users/jrs/anaconda/lib/python3.5/site-packages/seaborn/categorical.py in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
145 if isinstance(input, string_types):
146 err = "Could not interpret input '{}'".format(input)
--> 147 raise ValueError(err)
148
149 # Figure out the plotting orientation
ValueError: Could not interpret input 'senitment'
Run Code Online (Sandbox Code Playgroud)
我尝试在 df 上使用 .reset_index() 并更改数据类型,但没有运气。想法?
sns.violinplot(x="rank", y="sentiment", hue="category", data=df)
Run Code Online (Sandbox Code Playgroud)