Pandas gapminder

From RHS Wiki
Revision as of 10:45, 21 May 2019 by Rafahsolis (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
pip install pandas
pip install gapminder
pip install matplotlib
from gapminder import gapminder as df
import matplotlib.pyplot as plt

df.groupby('year')['lifeExp'].mean()

grouped_year_df =  df.groupby('year')
grouped_year_df_lifeExp = grouped_year_df['lifeExp']
grouped_year_df_lifeExp.mean()
df.groupby(['year', 'continent'])[['lifeExp', 'gdpPercap']].mean()

df.groupby('continent')['country'].nunique()

global_yearly_life_expectancy = df.groupby('year')['lifeExp'].mean()

# Plot
global_yearly_life_expectancy.plot()
plt.show()