Read epw file into a pandas dataframe?

Hello community,

I’d like to know if it is possible to read an EPW file into a pandas dataframe using ladybug (I found this function in pvlib iotools (https://pvlib-python.readthedocs.io/en/stable/generated/pvlib.iotools.read_epw.html))?

Thanks!

Long

@vlle

There isn’t a ladybug method that does this at this point. The closest thing would be Ladybug’s EPW module which has many useful properties and methods for interacting with the epw (converting from SI to IP, getting extreme, typical weeks etc). .

You could convert that into a dataframe like this (someone can correct me if there’s a more pythonic way to do this):

In my opinion, this is a lot better then just creating a dataframe from a raw epw file, i.e:

df = pd.read_csv(epw_path, dtype=float, skiprows=8, delimiter = ',')

Since you’d have to mess around with the epw data dictionary to get the desired weather data names (which isn’t included in the raw epw).

2 Likes

@SaeranVasanthakumar Thanks very much for your suggestion. It is useful.

Try this:

from ladybug.epw import EPW
from pandas import DataFrame
from collections import OrderedDict

#Path to epw file.
epwCls=EPW(r"assets/mannheim.epw")

epwDataList=epwCls.to_dict()['data_collections']
epwDataDict=OrderedDict()

for dataCol in  epwDataList:
    dataName=dataCol['header']['data_type']['name']
    epwDataDict[dataName]=dataCol['values']

epwDataFrame=DataFrame(epwDataDict)

Then this will give you the list of available hourly datasets:

#print all available columns
print(epwDataFrame.columns)

image

…and something like this will let you access individual datasets.

#Print dry bulb temperature
print(epwDataFrame["Dry Bulb Temperature"])

image

You can refine it further by creating a timeseries for the first column and specifying that as a date type.

Regards,
Sarith

3 Likes

Thanks a lot @sarith

Nice! I was wondering if there was a way to just get the hourly datasets.