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='iso-8859-1',
        header=0,
        index_col=None,
        parse_dates=None,  
        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.
    df['Von'] = df['Von'].str.replace(
        'A', '').str.replace('B', '')
    
    df['Von'] = pd.to_datetime(df['Von'], dayfirst=True,)
    
    df.set_index('Von', inplace=True)

    df.index = df.index.tz_localize('Europe/Vienna', ambiguous='infer')
    df.index = df.index.tz_convert(None)
    
    colmap = {
        'Wind  [MW]': {
            'variable': 'wind',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url
        },
        'Solar  [MW]': {
            'variable': 'solar',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url
        }
    }
    
    # Drop any column not in colmap
    df = df[list(colmap.keys())]
    
    # 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='iso-8859-1',
        header=0,
        index_col=None,
        parse_dates=None,  
        decimal=',',
        thousands='.',        
    )
    df['Von'] = df['Von'].str.replace(
        'A', '').str.replace('B', '')
    df['Von'] = pd.to_datetime(df['Von'], dayfirst=True,)
    df.set_index('Von', inplace=True)
    df.index = df.index.tz_localize('Europe/Vienna', ambiguous='infer')
    df.index = df.index.tz_convert(None)
    colmap = {
        'Wind  [MW]': {
            'variable': 'wind',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url
        },
        'Solar  [MW]': {
            'variable': 'solar',
            'region': 'AT',
            'attribute': 'generation',
            'source': 'APG',
            'web': url
        }
    }
    df = df[list(colmap.keys())]
    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 = 'iso-8859-1' , header = 0 , index_col = None , parse_dates = None , decimal = ',' , thousands = '.' , ) df [ 'Von' ] = df [ 'Von' ] . str . replace ( 'A' , '' ) . str . replace ( 'B' , '' ) df [ 'Von' ] = pd . to_datetime ( df [ 'Von' ] , dayfirst = True , ) df . set_index ( 'Von' , inplace = True ) df . index = df . index . tz_localize ( 'Europe/Vienna' , ambiguous = 'infer' ) df . index = df . index . tz_convert ( None ) colmap = { 'Wind  [MW]' : { 'variable' : 'wind' , 'region' : 'AT' , 'attribute' : 'generation' , 'source' : 'APG' , 'web' : url } , 'Solar  [MW]' : { 'variable' : 'solar' , 'region' : 'AT' , 'attribute' : 'generation' , 'source' : 'APG' , 'web' : url } } df = df [ list ( colmap . keys ( ) ) ] 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