s-celles
pandas_degreedays
Python

A Python package to calculate degree days (DD or in french DJU - degré jour unifié) from measured outdoor temperatures and to make it possible to quantify drift of energy consumption for heating (or cooling)

Last updated Jun 28, 2024
15
Stars
5
Forks
5
Issues
+15
Stars/day
Attention Score
5
Language breakdown
Python 100.0%
Files click to expand
README

Welcome to pandas\_degreedays's documentation! ==============================================

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

pandas\_degreedays ==================

Pandas Degree Days (pandasdegreedays) is a Python package to calculate degree days.

Usage


You must provide a Pandas Series with temperature values.

Let's call ts_temp this Serie which looks like:

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

You can get a time serie with temperature in sample folder and read it using:

import pandas as pd filename = 'temperature_sample.xls' dftemp = pd.readexcel(filename) dftemp = dftemp.set_index('datetime') tstemp = dftemp['temp']

You can also fetch a time serie with temperature from OpenWeatherMap.org. You need to install first openweathermap\_requests.

import logging logger = logging.getLogger() logger.setLevel(logging.DEBUG) from pandas_degreedays.provider import TemperatureProvider apikey = 'YOURAPI_KEY' tstemp = TemperatureProvider('OpenWeatherMap', apikey=apikey).getfrom_coordinates(0.34189, 46.5798114, '20150101', '20150915') #tstemp = TemperatureProvider('OpenWeatherMap', apikey=apikey).getfrom_place('Poitiers,FR', '20150101', '20150915')

We can see if some data are missing using:

idx = ts_temp.index s_idx = pd.Series(idx, index=idx) diffidx = sidx-s_idx.shift(1) ssamplingperiod = diffidx.valuecounts() samplingperiod = ssampling_period.index[0] # most prevalent sampling period notsamplingperiod = (diffidx != samplingperiod) # True / False

We can interpolate linearly missing data using:

from pandasdegreedays import interlin_nan tstemp = interlinnan(tstemp, '1H') # interpolates linearly NaN

We can calculate degree days using:

from pandasdegreedays import calculatedd dfdegreedays = calculatedd(ts_temp, method='pro', typ='heating', Tref=18.0, group='yearly')

method can be:

  • 'pro' (energy professionals) - this is default calculation method
  • 'meteo'
typ (calculation type) can be :
  • 'heating' - this is default calculation type
  • 'cooling'
Tref is reference temperature - default value is 18.0

group can be:

  • 'yearly' - this is default grouping option
  • 'yearly10' - same as 'yearly' but year starts in October (10)
  • 'monthly'
  • 'weekly'
  • None
  • Any lambda function that can be use and that can be applied to a datetime:
Example:

from pandasdegreedays import yearlymonth dfdegreedays = calculatedd(tstemp, method='pro', typ='heating', Tref=18.0, group=lambda dt: yearlymonth(dt, 10))

It outputs a Pandas DataFrame with degree days like:

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]

You can display plot using:

from pandasdegreedays import plottemp plottemp(tstemp, df_degreedays)

About Pandas


pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with "relational" or "labeled" data both easy and intuitive. It's a very convenient library to work with time series.

Install


From Python package index

$ pip install pandas_degreedays

From source

Get latest version using Git

$ git clone https://github.com/scls19fr/pandas_degreedays.git $ cd pandas_degreedays $ python setup.py install

Links


🔗 More in this category

© 2026 GitRepoTrend · s-celles/pandas_degreedays · Updated daily from GitHub