I’m using the Kepler exoplanet dataset.
After loading it, and running a simple transpose() on it, in order to get the rows as columns, I try a seaborn boxplot, as follows:
JavaScript
x
2
1
sns.boxplot(data=df_train.tail(3197), x='0')
2
This returns:
JavaScript
1
47
47
1
---------------------------------------------------------------------------
2
ValueError Traceback (most recent call last)
3
Input In [45], in <module>
4
----> 1 sns.boxplot(data=df_train.tail(3197), x='0')
5
6
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagesseaborn_decorators.py:46, in _deprecate_positional_args.<locals>.inner_f(*args, **kwargs)
7
36 warnings.warn(
8
37 "Pass the following variable{} as {}keyword arg{}: {}. "
9
38 "From version 0.12, the only valid positional argument "
10
( )
11
43 FutureWarning
12
44 )
13
45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
14
---> 46 return f(**kwargs)
15
16
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagesseaborncategorical.py:2243, in boxplot(x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth, whis, ax, **kwargs)
17
2231 @_deprecate_positional_args
18
2232 def boxplot(
19
2233 *,
20
( )
21
2240 **kwargs
22
2241 ):
23
-> 2243 plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
24
2244 orient, color, palette, saturation,
25
2245 width, dodge, fliersize, linewidth)
26
2247 if ax is None:
27
2248 ax = plt.gca()
28
29
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagesseaborncategorical.py:406, in _BoxPlotter.__init__(self, x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth)
30
402 def __init__(self, x, y, hue, data, order, hue_order,
31
403 orient, color, palette, saturation,
32
404 width, dodge, fliersize, linewidth):
33
--> 406 self.establish_variables(x, y, hue, data, orient, order, hue_order)
34
407 self.establish_colors(color, palette, saturation)
35
409 self.dodge = dodge
36
37
File c:usersmartiappdatalocalprogramspythonpython39libsite-packagesseaborncategorical.py:153, in _CategoricalPlotter.establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
38
151 if isinstance(var, str):
39
152 err = "Could not interpret input '{}'".format(var)
40
--> 153 raise ValueError(err)
41
155 # Figure out the plotting orientation
42
156 orient = infer_orient(
43
157 x, y, orient, require_numeric=self.require_numeric
44
158 )
45
46
ValueError: Could not interpret input '0'
47
I also attempted this:
JavaScript
1
2
1
sns.boxplot(df_train.tail(3197)['0'])
2
and got a KeyError: '0'
instead. What am I doing wrong? As far as I can tell, I’m doing the exact same thing as the first example on the official Seaborn website, here.
Advertisement
Answer
A workable example:
JavaScript
1
7
1
filepath = "exoTrain.csv"
2
3
df_train = pd.read_csv(filepath)
4
df_train = df_train.transpose()
5
6
print(df_train.columns)
7
This outputs: RangeIndex(start=0, stop=5087, step=1)
which shows us that the indices are actually integers, rather than strings e.g. ‘0’, ‘1’, ‘2’
Changing the code to sns.boxplot(data=df_train.tail(3197), x=0)
fixes the issue.