pandas output:
name type value 0 Town_1 serv_time 8 days 07:14:44 1 Town_2 serv_time 0 days 16:46:35 2 Town_3 serv_time 0 days 22:39:27 3 Town_4 serv_time 0 days 02:36:56 4 Town_5 serv_time 0 days 11:17:45 [2022-04-01 15:18:22][ERROR] - Neither the `x` nor `y` variable appears to be numeric.
and on python:
Plot(
type='bar',
data=new_data,
x='value',
hue='type',
y='name',
style='whitegrid',
)
def __create_bar(self):
sns.set_palette('Set2')
sns.despine()
plot = sns.barplot(ax=self.ax, x=self.x, y=self.y, hue=self.hue, data=self.data)
self.__set_legends()
if self.show:
return plt.show()
return self.__save(plot)
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.
new_data['value_seconds'] = new_data.value.dt.total_seconds()
Plot(
type='bar',
data=new_data,
x='value_seconds',
hue='type',
y='name',
style='whitegrid',
)