Export a table listing all NUTS2 regions with their (most current) data.

    Output is a CSV file and an Excel file, saved as 'characters.csv/.xlsx' in the output directory.

def indicator_summary_table():
    """Export a table listing all NUTS2 regions with their (most current) data.

    Output is a CSV file and an Excel file, saved as 'characters.csv/.xlsx' in the output directory.
    """
    # a database client/session to run queries in
    cl = client.get_client()
    session = cl.create_session()

    # Query regions and indicators separately, join them in pandas

    query = session.query(models.NUTS2Region.name,
                          models.NUTS2Region.key,
                          models.NUTS2Region.id)
    df = cl.df_query(query).set_index('id')

    # For each EuroStat indicator, query latest available data year (varies between indicators)
    indicators = session.query(models.EuroStatIndicator.description,
                               models.EuroStatIndicator.id).all()
    for description, indicator_id in indicators:
        latest_year = session.query(sa.func.max(models.EuroStatValue.year)) \
            .filter(models.EuroStatValue.indicator_id == indicator_id) \
            .scalar()

        query = session.query(models.EuroStatValue.value,
                              models.EuroStatValue.region_id) \
            .filter(models.EuroStatValue.indicator_id == indicator_id) \
            .filter(models.EuroStatValue.year == latest_year)
        values = cl.df_query(query).set_index('region_id')['value']

        # rename series to description + year, join to data table
        values.name = description + ' ' + str(latest_year)
        df = df.join(values, how='left')

    # Query and join in weather indicators
    query = session.query(models.ClimateValue.region_id,
                          models.ClimateValue.value,
                          models.ClimateIndicator.description) \
        .join(models.ClimateIndicator)
    weather = cl.df_query(query).dropna(how='any')

    # pivot different indicators to columns, join to data table
    weather = weather.set_index(['region_id', 'description'])['value'].unstack()
    df = df.join(weather, how='left')

    # write output as both CSV and Excel; do not include index column
    df.to_csv(path.join(out_dir, "nuts2_values.csv"), encoding='utf-8', index=False)
    df.to_excel(path.join(out_dir, "nuts2_values.xlsx"), encoding='utf-8', index=False)

    session.close()