The source

The codez

# Cell 1
%matplotlib inline
import pandas as pd
# Cell 2
def get_tmy(lat, lon):
    """Get a TMY timeseries for given location.
        lat: latitude (degrees) of location
        lon: longitude (degree) of location
        DataFrame of 9 climate indicators for all
        8760 hours of a year.
    import pandas as pd
    import requests
    from io import StringIO
    tmy_url = ""
    request_params = {
        'browser': 1,
        'format': 1,
        'startyear': 2006,
        'finalyear': 2015,
        'lat': lat,
        'lon': lon,
        'usehorizon': 0,
        'userhorizon': None}
    response = requests.get(tmy_url, request_params)
    decoded_response = response.content.decode(response.encoding)
    df = pd.read_csv(StringIO(decoded_response),
    df.columns = [c.strip() for c in df.columns]
    df['Date&Time (UTC)'] = pd.to_datetime(df['Date&Time (UTC)'])
    return df
def strip_tmy_for_interactive_use(df):
    """Make TMY timeseries DataFrame easier to use.
    Replaces verbose column names by short signifiers. Also, it
    replaces the individual years with 2019, so that pandas' 
    resample methods do not get confused with all the "missing"
    time between the individual months.
    new_column_names = {
        'Air pressure (Pa)': 'press',
        'Date&Time (UTC)': 'date',
        'Dry bulb temperature (deg. C)': 'temp',
        'Direct (beam) normal Irradiance (W/m2)': 'irr-direct',
        'Diffuse horizontal irradiance (W/m2)': 'irr-diffuse',
        'Global horizontal irradiance (W/m2)': 'irr-global',
        'Infrared radiation downwards (W/m2)': 'rad-down',
        'Relative Humidity (%)': 'humidity',
        'Windspeed (m/s)': 'wind-speed',
        'Wind direction (deg.)': 'wind-dir'}
    df = df.rename(columns=new_column_names)
    df['date'] = df['date'].apply(lambda dt: dt.replace(year=2019))
    return df