Difference between revisions of "Pandas gapminder"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) (Created page with "<syntaxhighlight lang="bash"> pip install pandas pip install gapminder </syntaxhighlight><syntaxhighlight lang="python3"> from gapminder import gapminder as df df.groupby('yea...") Tag: visualeditor |
Rafahsolis (talk | contribs) m Tag: visualeditor |
||
| (One intermediate revision by the same user not shown) | |||
| Line 2: | Line 2: | ||
pip install pandas | pip install pandas | ||
pip install gapminder | pip install gapminder | ||
| + | pip install matplotlib | ||
</syntaxhighlight><syntaxhighlight lang="python3"> | </syntaxhighlight><syntaxhighlight lang="python3"> | ||
from gapminder import gapminder as df | from gapminder import gapminder as df | ||
| + | import matplotlib.pyplot as plt | ||
| + | |||
df.groupby('year')['lifeExp'].mean() | df.groupby('year')['lifeExp'].mean() | ||
| Line 14: | Line 17: | ||
global_yearly_life_expectancy = df.groupby('year')['lifeExp'].mean() | global_yearly_life_expectancy = df.groupby('year')['lifeExp'].mean() | ||
| + | |||
| + | # Plot | ||
| + | global_yearly_life_expectancy.plot() | ||
| + | plt.show() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 10:45, 21 May 2019
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()