matplotlib可视化练习 -- 航班乘客数据分析

2017-09-10  本文已影响160人  b485c88ab697

matplotlib可视化练习

%matplotlib inline
import matplotlib as mpl
from matplotlib import pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
data = sns.load_dataset("flights")
data.head()
# 年份,月份,乘客数
Paste_Image.png

聚合求出每年的旅客数量

data_number = data.groupby(data['year']).sum()
data_number
Paste_Image.png
plt.plot(data_number.index,data_number.values)
output_6_1.png

各个月的分布

data_number = data[['month','passengers']].groupby(['month']).sum()
data_number = pd.Series(data_number['passengers'].values,index=(np.arange(1,13,1)))
data_number
1     2901
2     2820
3     3242
4     3205
5     3262
6     3740
7     4216
8     4213
9     3629
10    3199
11    2794
12    3142
dtype: int64
plt.bar(data_number.index,data_number.values)
output_9_1.png
上一篇下一篇

猜你喜欢

热点阅读