def quiet_days(series,
n_days=5,
period='min'):
"""
Given a pandas time series *series*, return a mapping between
months and the *n_days* quietest days for that month. See (4) of
Love and Gannon. The parameter *period* gives the sampling period
(`'min'` = 1 measurement per minute).
"""
quiet_day_map = {}
delta_H_i = series.diff().abs().\
groupby(PD.TimeGrouper(freq='D')).\
filter(lambda x: x.isnull().sum() <= int(0.5 * SAMPLES[period])).\
groupby(PD.TimeGrouper(freq='D')).mean()
for month, delta_H_i_month in delta_H_i.groupby(PD.TimeGrouper(freq='M')):
quiet_day_map[month] = delta_H_i_month.nsmallest(n_days).sort_index().index
return quiet_day_map
评论列表
文章目录