问题
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