跳转到主要内容

度日数据

项目描述

欢迎使用pandas_degreedays文档!

Latest Version Supported Python versions Wheel format License Development Status Downloads monthly Documentation Status Sourcegraph Gitter Code Health Build Status

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

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码发行版

pandas_degreedays-0.0.6.tar.gz (9.4 kB 查看哈希值)

上传时间 源代码

构建发行版

pandas_degreedays-0.0.6-py2.py3-none-any.whl (12.8 kB 查看哈希值)

上传时间 Python 2 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页