0

I have a data set which has video games, their sales, and the year the game was released. I am only looking for the game sales per year, not the game sales per title per year.

I am using a pandas Dataframe. I have tried a groupby method. I have tried a loop with .unique() values.

df = df[["Year", "NA_Sales"]]
df.Year = df.Year.astype(int)
df2 = df
df2.Year = df.Year.unique()

df2 = df.groupby(['Year'])['NA_Sales'].sum()

The expected result would be a dataframe including one column of unique year values, and one column of all video game sales for that year

1
  • df.groupby(['Year'])['NA_Sales'].sum().reset_index() ? Commented Oct 25, 2019 at 14:17

2 Answers 2

1

You can use

df.groupby('Year', as_index=False)['NA_Sales'].sum()
Sign up to request clarification or add additional context in comments.

Comments

0

This worked for me:

import pandas as pd

path = r'your path'
wb = pd.read_excel(path)
df =  pd.DataFrame(wb)
df.style.hide_index()
df1 = df[['YEAR', 'NA_SALES']]
GB=df1.groupby([df1['YEAR']]).sum()

Make sure that when you create the DataFrame the dtype is not a str.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.