度日数据
项目描述
欢迎使用pandas_degreedays文档!
pandas_degreedays
Pandas Degree Days (pandas_degreedays) 是一个 Python 包,用于计算 度日数据。
用法
您必须提供一个包含温度值的 Pandas Series。
让我们称这个Series为ts_temp,它看起来像
datetime 2014-03-20 23:00:00 11 2014-03-20 23:30:00 11 2014-03-21 00:00:00 11 2014-03-21 00:30:00 11 2014-03-21 01:00:00 11 2014-03-21 01:30:00 11 ... 2014-11-01 20:00:00 12 2014-11-01 20:30:00 12 2014-11-01 21:00:00 12 2014-11-01 21:30:00 12 2014-11-01 22:00:00 12 2014-11-01 22:30:00 12 Name: temp, Length: 10757
您可以从sample文件夹中获取包含温度的时间序列,并使用以下方法读取它:
import pandas as pd filename = 'temperature_sample.xls' df_temp = pd.read_excel(filename) df_temp = df_temp.set_index('datetime') ts_temp = df_temp['temp']
您也可以从 OpenWeatherMap.org 获取包含温度的时间序列。您首先需要安装 openweathermap_requests。
import logging logger = logging.getLogger() logger.setLevel(logging.DEBUG) from pandas_degreedays.provider import TemperatureProvider ts_temp = TemperatureProvider('OpenWeatherMap', api_key='').get_from_coordinates(0.34189, 46.5798114, '20120601', '20141215')
使用以下方法可以查看是否存在缺失数据:
idx = ts_temp.index s_idx = pd.Series(idx, index=idx) diff_idx = s_idx-s_idx.shift(1) s_sampling_period = diff_idx.value_counts() sampling_period = s_sampling_period.index[0] # most prevalent sampling period not_sampling_period = (diff_idx != sampling_period) # True / False
我们可以使用以下方法对缺失数据进行线性插值:
from pandas_degreedays import inter_lin_nan ts_temp = inter_lin_nan(ts_temp, '1H') # interpolates linearly NaN
我们可以使用以下方法计算度日数据:
from pandas_degreedays import calculate_dd df_degreedays = calculate_dd(ts_temp, method='pro', typ='heating', Tref=18.0, group='yearly')
method 可以是
- 'pro'(能源专业人士)- 这是默认计算方法 - 'meteo'
typ(计算类型)可以是
- 'heating' - 这是默认计算类型 - 'cooling'
Tref 是参考温度 - 默认值为 18.0
group 可以是
- 'yearly' - 默认分组选项 - 'yearly10' - 与 'yearly' 相同,但年份从10月(10)开始 - 'monthly' - 'weekly' - None - 任何可以用于并应用于 datetime 的 lambda 函数
from pandas_degreedays import yearly_month df_degreedays = calculate_dd(ts_temp, method='pro', typ='heating', Tref=18.0, group=lambda dt: yearly_month(dt, 10))
它输出一个包含度日数据的 Pandas DataFrame
Tmin Tmax Tavg Tref DD DD_cum 2014-03-22 7.0 11.0 9.00 18 9.000000 9.000000 2014-03-23 3.0 12.0 7.50 18 10.500000 19.500000 2014-03-24 0.0 10.0 5.00 18 13.000000 32.500000 2014-03-25 6.0 10.0 8.00 18 10.000000 42.500000 2014-03-26 5.0 12.0 8.50 18 9.500000 52.000000 2014-03-27 2.0 8.0 5.00 18 13.000000 65.000000 ... ... ... ... ... ... ... 2014-10-26 5.0 17.0 11.00 18 7.000000 653.547663 2014-10-27 9.0 22.0 15.50 18 3.336923 656.884586 2014-10-28 7.5 20.0 13.75 18 4.544400 661.428986 2014-10-29 8.0 19.0 13.50 18 4.618182 666.047168 2014-10-30 12.0 22.0 17.00 18 1.992000 668.039168 2014-10-31 11.0 24.0 17.50 18 2.143077 670.182245 [224 rows x 6 columns]
您可以使用以下方式显示图形
from pandas_degreedays import plot_temp plot_temp(ts_temp, df_degreedays)
关于 Pandas
pandas 是一个 Python 包,提供快速、灵活、易于表达的数据结构,旨在使处理“关系”或“标记”数据变得既简单又直观。这是一个非常方便的库,用于处理时间序列。
安装
从 Python 软件包索引
$ pip install pandas_degreedays
从源代码
使用 Git 获取最新版本
$ git clone https://github.com/scls19fr/pandas_degreedays.git $ cd pandas_degreedays $ python setup.py install
链接
文档可在 Read The Docs 中找到;
源代码和问题跟踪可在 GitHub 中找到。
请随意 打赏 我!
项目详情
下载文件
下载您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码发行版
pandas_degreedays-0.0.6.tar.gz (9.4 kB 查看哈希值)
构建发行版
关闭
哈希值 for pandas_degreedays-0.0.6-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 053263517a3b159e024b7429bf4e020f305571eb32e688d15ee99b79d25afa01 |
|
MD5 | 5e80195a2f5cfba7ebb9dfb59baf2353 |
|
BLAKE2b-256 | f41b859faef056cedf3cc71a62a88426e075e6e70a8a3ff38b2fab8841e1e184 |