注解

此笔记本可在此处下载: 02_DATA_WeatherStation.ipynb

#Setup
%load_ext autoreload
%matplotlib nbagg
%autoreload 2
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import animation, rc, cm
rc('animation', html='html5')

实际工作:分析气象站的数据

本节课的目的是强调使用熊猫模块的温度数据演变。

这些数据是在瑞士的“圣伯纳德大峡谷”站测量的。可在以下地址下载数据:https://www.noaa.gov/

问题

问题1 :加载数据库并观察不同字段。

问题2 :日期数据的类型是什么?使用pandas函数 to_datetime() 将其转换为日期类型的数据。

问题3 :绘制温度与时间的关系图。他们丢失了数据吗?

问题4 :计算各温度的年平均值(TMIN、TAVG、TMAX)?然后策划它。

date对象允许访问日期信息。如果D是日期对象: * D.dt.year 给出日期的年份 * D.dt.month 给出日期的月份

问题6 :一年中逐月的平均温度分布是多少?对1860年至1900年的数据进行平均计算。把它画出来。

问题7 :计算此基准年与以后年份(1960年至2020年)之间的差距。

问题8 :使绘图看起来像已知的gif:

# an exemple to do an annimation
T = np.linspace(0,10,100)
mrad = np.linspace(0,6*np.pi,100)
def updatefig(i):
    line.set_data(mrad[:i], T[:i])
    #time_text.set_text('Year = {:}'.format(dfby.index.get_level_values(0)[i]))
    return line,time_text


fig, ax = plt.subplots()
ax.axis('off')
line, = plt.polar([], [],'-.', animated=True)
time_text = ax.text(0.02, 0.95, '', transform=ax.transAxes)
plt.ylim([-1, 10])


anim = animation.FuncAnimation(fig, updatefig, frames=100, interval=10, blit=True)
anim