pandas output:
JavaScript
x
8
1
name type value
2
0 Town_1 serv_time 8 days 07:14:44
3
1 Town_2 serv_time 0 days 16:46:35
4
2 Town_3 serv_time 0 days 22:39:27
5
3 Town_4 serv_time 0 days 02:36:56
6
4 Town_5 serv_time 0 days 11:17:45
7
[2022-04-01 15:18:22][ERROR] - Neither the `x` nor `y` variable appears to be numeric.
8
and on python:
JavaScript
1
21
21
1
Plot(
2
type='bar',
3
data=new_data,
4
x='value',
5
hue='type',
6
y='name',
7
style='whitegrid',
8
9
)
10
11
12
def __create_bar(self):
13
sns.set_palette('Set2')
14
sns.despine()
15
16
plot = sns.barplot(ax=self.ax, x=self.x, y=self.y, hue=self.hue, data=self.data)
17
self.__set_legends()
18
if self.show:
19
return plt.show()
20
return self.__save(plot)
21
i am trying do barplot in seaborn, but i get error numeric. How use sum time value in barplot seaborn?
Advertisement
Answer
You need to convert value series to a numeric data type to plot it.
For example, assuming that value has a timedelta dtype. You can create another column in your dataframe.
JavaScript
1
12
12
1
new_data['value_seconds'] = new_data.value.dt.total_seconds()
2
3
Plot(
4
type='bar',
5
data=new_data,
6
x='value_seconds',
7
hue='type',
8
y='name',
9
style='whitegrid',
10
11
)
12