Read CSV malformed (3 csv concatenated) in a single URL call

随声附和 提交于 2020-05-16 22:01:40

问题


I'm trying to read this CSV: https://re.jrc.ec.europa.eu/api/tmy?lat=41&lon=22&startyear=2007

And right now I'm doing 3 calls to parse it, since its structure is inconsistent. (they are basically 3 csv concatenated, with 3 indexes in between)

url = 'https://re.jrc.ec.europa.eu/api/tmy?lat=41&lon=22&startyear=2007'
MetaData = pd.read_csv(url,sep=":", nrows=3,names=['key','value'])
# do something with metadata
MonthData = pd.read_csv(url,skiprows=3,nrows=12)
# do something with the year 
Data = pd.read_csv(url,skiprows=16, skipfooter=11, engine='python')
# do something with the actual data

Is there a better way to do so?


回答1:


Use pvlib.iotools.get_pvgis_tmy

from pvgis.iotools import get_pvgis_tmy

lat=41
lon=22
startyear=2007

data, months, inputs, meta = get_pvgis_tmy(lat, lon, startyear=startyear)

This example and its output are in this Google Colaboratory Notebook: SO-get_pvgis.ipynb

Here are some plots form the notebook comparing the PVGIS components with predictions from Haurwitz and Erbs:

Compare GHI

Compare DNI

Compare DHI

If you're more interested in the codebase, check out the pvlib source at GitHub and contribute!

Thanks!



来源:https://stackoverflow.com/questions/61366516/read-csv-malformed-3-csv-concatenated-in-a-single-url-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!