0

I am working with a pandas dataframe and performing the plots and tables as the following. Here is a sample of the data;

companyID,county,city,companytype,turnover_class,customertype,sni,emp_class,yearmonth,productcode,sales,month,day,weekday,year,subproduct 0,127,S ,180,81,11,B5,20150,14,2015-04-01,Övrigt,205940,4,1,Wednesday,2015,Kolhydrater 1,127,S ,180,81,11,B5,20150,14,2015-05-01,Övrigt,1088628,5,1,Friday,2015,Kolhydrater 2,127,S ,180,81,11,B5,20150,14,2015-06-01,Övrigt,264358,6,1,Monday,2015,Kolhydrater 3,127,S ,180,81,11,B5,20150,14,2015-06-01,Övrigt,521313,6,1,Monday,2015,Godis 4,127,S ,180,81,11,B5,20150,14,2015-06-01,Övrigt,795825,6,1,Monday,2015,Godis 5,127,S ,180,81,11,B5,20150,14,2015-07-01,Övrigt,107325,7,1,Wednesday,2015,Kolhydrater 6,127,S ,180,81,11,B5,20150,14,2015-07-01,Övrigt,576303,7,1,Wednesday,2015,Godis 7,127,S ,180,81,11,B5,20150,14,2015-08-01,Övrigt,1137793,8,1,Saturday,2015,Kolhydrater 8,127,S ,180,81,11,B5,20150,14,2015-08-01,Övrigt,13308,8,1,Saturday,2015,Godis 9,127,S ,180,81,11,B5,20150,14,2015-08-01,Övrigt,80975,8,1,Saturday,2015,Godis 10,127,S ,180,81,11,B5,20150,14,2015-09-01,Övrigt,662355,9,1,Tuesday,2015,Godis

sns.lineplot(data=df_replace_code3,x='subproduct',y='sales',hue='productcode',markers=True,style='productcode',dashes=False)

sns.lineplot

product_sales = pd.pivot_table(data=df_replace_code3, index=['productcode', 'subproduct'], values='sales', 
           aggfunc='sum').reset_index().sort_values(['productcode', 'sales'], ascending=False)

product_sales

pivot table

and

from pickle import TRUE


plt.rcParams['figure.figsize'] = (15,22)

ax = plt.axes()
ax.set_facecolor('#2F2F2F')

sns.barplot(y='subproduct', x='sales', data=df_replace_code3, hue='productcode')

bbox_args = dict(boxstyle = 'round', fc = '1')
for p in ax.patches:
    width = p.get_width()
    plt.text(p.get_width(), p.get_y() + 0.5 * p.get_height(), '{:1.0f}'.format(width), 
             ha = 'center', 
             va = 'center', 
             color = 'black', 
             bbox = bbox_args, 
             fontsize = 13)

plt.title('Sales by product & sub product', fontsize = 18)
plt.ylabel(None)
plt.tick_params(left=False, bottom=False, labelbottom=False)
plt.show()

sns barplot

My question is that how interpret the plots and why the numbers in table is different with the numbers in barplot and lineplot?

Berke
  • 69
  • 2
  • 3
  • 12
  • Could you please add your test data in text (or code) format? – JohanC Sep 16 '22 at 10:47
  • Note that in your pivot table, you calculate sums, while for the bar plot you take the default (being averages and their deviation). The lineplot is a bit similar to the barplot, but, as the x-axis of the lineplot isn't numeric, the lines don't make much sense. – JohanC Sep 16 '22 at 10:52
  • Note that in your pivot table, you calculate sums, while for the bar plot you take the default (being averages and their deviation). The lineplot is a bit similar to the barplot, but, as the x-axis of the lineplot isn't numeric, the lines don't make much sense. As each of the subcategories belongs to exactly one category, there will be exactly one bar per subcategory. You can use `dodge=False` to put that bar centered at the subcategory name. – JohanC Sep 16 '22 at 10:58
  • Thanks @JohanC, I added a sample of data. – Berke Sep 16 '22 at 11:09
  • Please, never add data as image https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question – JohanC Sep 16 '22 at 11:12

0 Answers0