0

I want to create a lineplot showing the commuted sales per publisher per year. For this I want to group per year and per publisher before but then I have no indexes anymore.

sales_per_year = df.groupby(['Publisher', 'Year'], as_index=False)['Global_Sales'].cumsum()
sns.lineplot(data=sales_per_year, x='Year', y='Global_Sales', hue='Platform')
Global_Sales
0 82.74
1 40.24
2 35.82
3 33.00
4 31.37
Nasgull
  • 1
  • 1
  • You can reset the index, see for example [pandas reset_index after groupby.value_counts()](https://stackoverflow.com/questions/39778686/pandas-reset-index-after-groupby-value-counts) – MagnusO_O Sep 25 '22 at 12:22
  • where is the rest of the code? https://stackoverflow.com/help/minimal-reproducible-example – D.L Sep 25 '22 at 12:50

1 Answers1

0

Instead of assigning groupby result to new df, what if we add that as new column in already existing dataframe... so try this maybe;

df["Global_Sales_Cumsum"] = df.groupby(['Publisher', 'Year'])['Global_Sales'].cumsum()

Now just call df instead of sales_per_year while plotting... Hope this Helps...

Sachin Kohli
  • 1,956
  • 1
  • 1
  • 6