In [1]:
import pandas as pd
df = pd.read_csv("./data/gapminder.tsv", sep="\t")
In [2]:
print(df.head(n=10))
groupby¶
In [3]:
print(df.groupby("year")["lifeExp"].mean())
print("\n======================================\n")
print(df.groupby("continent")["country"].nunique())
print("\n======================================\n")
In [4]:
df.groupby(["year", "continent"])["lifeExp"].mean()
Out[4]:
graph¶
In [5]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (12, 9)
plt.rcParams['axes.unicode_minus'] = False
In [6]:
lifeExp = df.groupby("year")["lifeExp"].mean()
lifeExp.plot()
plt.show()
In [7]:
from IPython.core.display import display, HTML
display(HTML("<style> .container{width:100% !important;}</style>"))
'pandas > basic' 카테고리의 다른 글
06.handling_dataframe(bool) (0) | 2018.12.09 |
---|---|
05.handling_series(apply) (0) | 2018.12.09 |
04.handling_series(basic) (0) | 2018.12.09 |
03.create_data_frame (0) | 2018.12.09 |
01.data_slicing (0) | 2018.12.09 |