Pandas Dataframes

Let’s now use the Sum function in a dataframe instead of the average (mean) function.

Code:

import pandas as pd

df = pd.read_excel('europe_cities_by_sunshine.xlsx')

df = df[['Country', 'Year']]

df = df.groupby(by=["Country"]).sum()

Explanation:

Now, we switched out the mean() function for the sum() function so we’ll add up all the Year values for each country, and group it together. So now Cyprus’s value increased since it’s no longer an average, but the addition.