timeseries_scripts/read.py
def read_apg(filepath, url, headers):
    '''Read a file from APG into a DataFrame'''
    df = pd.read_csv(
        filepath,
        sep=';',
        encoding='latin_1',
        header=0,
        index_col='timestamp',
        parse_dates={'timestamp': ['Von']},
        dayfirst=True,
        decimal=',',
        thousands='.',
        # Format of the raw_hour-column is normally is 01:00:00, 02:00:00 etc.
        # during the year, but 3A:00:00, 3B:00:00 for the (possibely
        # DST-transgressing) 3rd hour of every day in October, we truncate the
        # hours column after 2 characters and replace letters which are there to
        # indicate the order during fall DST-transition.
        converters={'Von': lambda x: str(x).replace('A', '').replace('B', '')}
    )

    df.index = df.index.tz_localize('Europe/Vienna', ambiguous='infer')
    df.index = df.index.tz_convert(None)

    colmap = {
        'Wind [MW]': {
            'variable': 'wind_onshore',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url,
            'unit': 'MW'
        },
        'Solar [MW]': {
            'variable': 'solar',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url,
            'unit': 'MW'
        },
        'Wind  [MW]': {
            'variable': 'wind_onshore',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url,
            'unit': 'MW'
        },
        'Solar  [MW]': {
            'variable': 'solar',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url,
            'unit': 'MW'
        }
    }

    # Drop any column not in colmap
    df = df[[key for key in colmap.keys() if key in df.columns]]

    # Create the MultiIndex
    tuples = [tuple(colmap[col][level] for level in headers)
              for col in df.columns]
    df.columns = pd.MultiIndex.from_tuples(tuples, names=headers)

    return df
Read a file from APG into a DataFrame
Read a file from APG into a DataFrame
Read a file from APG into a DataFrame
def read_apg(filepath, url, headers):
    df = pd.read_csv(
        filepath,
        sep=';',
        encoding='latin_1',
        header=0,
        index_col='timestamp',
        parse_dates={'timestamp': ['Von']},
        dayfirst=True,
        decimal=',',
        thousands='.',
        converters={'Von': lambda x: str(x).replace('A', '').replace('B', '')}
    )
    df.index = df.index.tz_localize('Europe/Vienna', ambiguous='infer')
    df.index = df.index.tz_convert(None)
    colmap = {
        'Wind [MW]': {
            'variable': 'wind_onshore',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url,
            'unit': 'MW'
        },
        'Solar [MW]': {
            'variable': 'solar',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url,
            'unit': 'MW'
        },
        'Wind  [MW]': {
            'variable': 'wind_onshore',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url,
            'unit': 'MW'
        },
        'Solar  [MW]': {
            'variable': 'solar',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url,
            'unit': 'MW'
        }
    }
    df = df[[key for key in colmap.keys() if key in df.columns]]
    tuples = [tuple(colmap[col][level] for level in headers)
              for col in df.columns]
    df.columns = pd.MultiIndex.from_tuples(tuples, names=headers)
    return df
def read_apg ( filepath , url , headers ) : df = pd . read_csv ( filepath , sep = ';' , encoding = 'latin_1' , header = 0 , index_col = 'timestamp' , parse_dates = { 'timestamp' : [ 'Von' ] } , dayfirst = True , decimal = ',' , thousands = '.' , converters = { 'Von' : lambda x : str ( x ) . replace ( 'A' , '' ) . replace ( 'B' , '' ) } ) df . index = df . index . tz_localize ( 'Europe/Vienna' , ambiguous = 'infer' ) df . index = df . index . tz_convert ( None ) colmap = { 'Wind [MW]' : { 'variable' : 'wind_onshore' , 'region' : 'AT' , 'attribute' : 'generation' , 'source' : 'APG' , 'web' : url , 'unit' : 'MW' } , 'Solar [MW]' : { 'variable' : 'solar' , 'region' : 'AT' , 'attribute' : 'generation' , 'source' : 'APG' , 'web' : url , 'unit' : 'MW' } , 'Wind  [MW]' : { 'variable' : 'wind_onshore' , 'region' : 'AT' , 'attribute' : 'generation' , 'source' : 'APG' , 'web' : url , 'unit' : 'MW' } , 'Solar  [MW]' : { 'variable' : 'solar' , 'region' : 'AT' , 'attribute' : 'generation' , 'source' : 'APG' , 'web' : url , 'unit' : 'MW' } } df = df [ [ key for key in colmap . keys ( ) if key in df . columns ] ] tuples = [ tuple ( colmap [ col ] [ level ] for level in headers ) for col in df . columns ] df . columns = pd . MultiIndex . from_tuples ( tuples , names = headers ) return df
Read a file from APG into a DataFrame
Read a file from APG into a DataFrame
'''Read a file from APG into a DataFrame''' # Format of the raw_hour-column is normally is 01:00:00, 02:00:00 etc. # during the year, but 3A:00:00, 3B:00:00 for the (possibely # DST-transgressing) 3rd hour of every day in October, we truncate the # hours column after 2 characters and replace letters which are there to # indicate the order during fall DST-transition. # Drop any column not in colmap # Create the MultiIndex
filepath
url
headers