pandas Python Seaborn 绘图 ValueError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43190850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python Seaborn Plot ValueError
提问by Ryan
I have a pandas dataframe df
and am trying to use the seaborn library to create a violin plot.
我有一个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
This is the seaborn line:
这是seaborn线:
sns.violinplot(x="rank", y="senitment", hue="category", data=df)
I keep getting this ValueError
我一直得到这个 ValueError
ValueError: Could not interpret input 'senitment'
Full traceback
完整追溯
/Users/jrs/anaconda/lib/python3.5/site-packages/seaborn/categorical.py in violinplot(x, y, hue, data, order, hue_order, bw, cut, scale, scale_hue, gridsize, width, inner, split, orient, linewidth, color, palette, saturation, ax, **kwargs) 2299 bw, cut, scale, scale_hue, gridsize, 2300 width, inner, split, orient, linewidth, -> 2301 color, palette, saturation) 2302 2303 if ax is None:
/Users/jrs/anaconda/lib/python3.5/site-packages/seaborn/categorical.py in violinplot(x,y,hue,data,order,hue_order,bw,cut,scale,scale_hue,gridsize,width,inner , 分割, 方向, 线宽, 颜色, 调色板, 饱和度, ax, **kwargs) 2299 bw, cut, scale, scale_hue, gridsize, 2300 width, internal, split, orient, linewidth, -> 2301 color,调色板,饱和度) 2302 2303 如果 ax 为 None:
/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'
I've tried using .reset_index() on the df and changing data types, but no luck. Thoughts?
我试过在 df 上使用 .reset_index() 并更改数据类型,但没有运气。想法?
回答by Scott Boston
sns.violinplot(x="rank", y="sentiment", hue="category", data=df)