Reputation: 47
I have this data frame:
df = {'DATE': [43390, 43599, 43605, 43329, 43440],
'STORE': [1, 1, 1, 2, 2],
'LYLTY_CARD_NBR': [1000, 1307, 1343, 2373, 2426],
'TXN_ID': [1, 348, 383, 974, 1038],
'PROD_QTY': [2, 3, 2, 5, 3],
'TOT_SALES': [6.0, 6.3, 2.9, 15.0, 13.8]}
transac = pd.DataFrame(df)
DATE STORE LYLTY_CARD_NBR TXN_ID PROD_QTY TOT_SALES
0 43390 1 1000 1 2 6.0
1 43599 1 1307 348 3 6.3
2 43605 1 1343 383 2 2.9
3 43329 2 2373 974 5 15.0
4 43440 2 2426 1038 3 13.8
When I try to plot a boxplot from seaborn of the TOT_SALES column I get this error. The type of the column is float64. I tried the same with matplotlib and it worked but not with seaborn:
sns.boxplot(y='TOT_SALES', df=transac)
ValueError Traceback (most recent call last)
<ipython-input-16-29f35d075db2> in <module>
----> 1 sns.boxplot(y='TOT_SALES', df=transac)
~\Anaconda3\lib\site-packages\seaborn\categorical.py in boxplot(x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth, whis, ax, **kwargs)
2239 plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
2240 orient, color, palette, saturation,
-> 2241 width, dodge, fliersize, linewidth)
2242
2243 if ax is None:
~\Anaconda3\lib\site-packages\seaborn\categorical.py in __init__(self, x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth)
441 width, dodge, fliersize, linewidth):
442
--> 443 self.establish_variables(x, y, hue, data, orient, order, hue_order)
444 self.establish_colors(color, palette, saturation)
445
~\Anaconda3\lib\site-packages\seaborn\categorical.py in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
150 if isinstance(var, str):
151 err = "Could not interpret input '{}'".format(var)
--> 152 raise ValueError(err)
153
154 # Figure out the plotting orientation
ValueError: Could not interpret input 'TOT_SALES'
Where is the problem?
Upvotes: 3
Views: 45221
Reputation: 31011
The source of your error is that you passed transac as df parameter, which is not used by seaborn. Pass it as data instead:
sns.boxplot(y='TOT_SALES', data=transac);
Upvotes: 25