timeseries_scripts/imputation.py
def my_interpolate(
        i, j, nan_region, col, col_name, marker_col, nan_regs, one_period, message):
    '''
    Interpolate one missing value region in one column as described by 
    nan_region.

    The default pd.Series.interpolate() function does not work if
    interpolation is to be restricted to periods of a certain length.
    (A limit-argument can be specified, but it results in longer periods 
    of missing data to be filled parcially) 

    Parameters
    ----------
    i : int
        Counter for total number of regions of missing data
    j : int
        Counter for number regions of missing data not treated by by this
        function
    nan_region : pandas.Series
        Contains information on one region of missing data in col
        count: 
        span:
        start_idx:
        till_idx:
    See choose_fill_method() for info on other parameters.

    Returns
    ----------
    col : pandas.DataFrame
        The column with all nan_regs treated for periods shorter than 1:15.

    '''
    if i + 1 == len(nan_regs):
        treated = i + 1 - j
        logger.info(message + 'interpolated %s up-to-2-hour-span(s) of NaNs',
                    treated)

    to_fill = slice(nan_region['start_idx'] - one_period,
                    nan_region['till_idx'] + one_period)
    comment_now = slice(nan_region['start_idx'], nan_region['till_idx'])

    col.iloc[:, 0].loc[to_fill] = col.iloc[:, 0].loc[to_fill].interpolate()

    # Create a marker column to mark where data has been interpolated
    col_name_str = '_'.join(
        [level for level in col_name[0:3] if not level == ''])

    comment_before = marker_col.notnull()
    comment_again = comment_before.loc[comment_now]
    if comment_again.any():
        marker_col[comment_before & comment_again] = marker_col + \
            ' | ' + col_name_str
    else:
        marker_col.loc[comment_now] = col_name_str

    return col, marker_col

    Interpolate one missing value region in one column as described by 
    nan_region.

    The default pd.Series.interpolate() function does not work if
    interpolation is to be restricted to periods of a certain length.
    (A limit-argument can be specified, but it results in longer periods 
    of missing data to be filled parcially) 

    Parameters
    ----------
    i : int
        Counter for total number of regions of missing data
    j : int
        Counter for number regions of missing data not treated by by this
        function
    nan_region : pandas.Series
        Contains information on one region of missing data in col
        count: 
        span:
        start_idx:
        till_idx:
    See choose_fill_method() for info on other parameters.

    Returns
    ----------
    col : pandas.DataFrame
        The column with all nan_regs treated for periods shorter than 1:15.

    
Interpolate one missing value region in one column as described by
nan_region.

The default pd.Series.interpolate() function does not work if
interpolation is to be restricted to periods of a certain length.
(A limit-argument can be specified, but it results in longer periods
of missing data to be filled parcially)

Parameters



Returns

col : pandas.DataFrame
The column with all nan_regs treated for periods shorter than 1:15.
Interpolate one missing value region in one column as described by nan_region . The default pd . Series . interpolate () function does not work if interpolation is to be restricted to periods of a certain length . ( A limit - argument can be specified but it results in longer periods of missing data to be filled parcially ) Parameters Returns col : pandas . DataFrame The column with all nan_regs treated for periods shorter than 1 : 15 .
def my_interpolate(
        i, j, nan_region, col, col_name, marker_col, nan_regs, one_period, message):
    if i + 1 == len(nan_regs):
        treated = i + 1 - j
        logger.info(message + 'interpolated %s up-to-2-hour-span(s) of NaNs',
                    treated)
    to_fill = slice(nan_region['start_idx'] - one_period,
                    nan_region['till_idx'] + one_period)
    comment_now = slice(nan_region['start_idx'], nan_region['till_idx'])
    col.iloc[:, 0].loc[to_fill] = col.iloc[:, 0].loc[to_fill].interpolate()
    col_name_str = '_'.join(
        [level for level in col_name[0:3] if not level == ''])
    comment_before = marker_col.notnull()
    comment_again = comment_before.loc[comment_now]
    if comment_again.any():
        marker_col[comment_before & comment_again] = marker_col + \
            ' | ' + col_name_str
    else:
        marker_col.loc[comment_now] = col_name_str
    return col, marker_col
def my_interpolate ( i , j , nan_region , col , col_name , marker_col , nan_regs , one_period , message ) : if i + 1 == len ( nan_regs ) : treated = i + 1 - j logger . info ( message + 'interpolated %s up-to-2-hour-span(s) of NaNs' , treated ) to_fill = slice ( nan_region [ 'start_idx' ] - one_period , nan_region [ 'till_idx' ] + one_period ) comment_now = slice ( nan_region [ 'start_idx' ] , nan_region [ 'till_idx' ] ) col . iloc [ : , 0 ] . loc [ to_fill ] = col . iloc [ : , 0 ] . loc [ to_fill ] . interpolate ( ) col_name_str = '_' . join ( [ level for level in col_name [ 0 : 3 ] if not level == '' ] ) comment_before = marker_col . notnull ( ) comment_again = comment_before . loc [ comment_now ] if comment_again . any ( ) : marker_col [ comment_before & comment_again ] = marker_col + ' | ' + col_name_str else : marker_col . loc [ comment_now ] = col_name_str return col , marker_col
Interpolate one missing value region in one column as described by
nan_region.
Interpolate one missing value region in one column as described by nan_region .
'''
    Interpolate one missing value region in one column as described by 
    nan_region.

    The default pd.Series.interpolate() function does not work if
    interpolation is to be restricted to periods of a certain length.
    (A limit-argument can be specified, but it results in longer periods 
    of missing data to be filled parcially) 

    Parameters
    ----------
    i : int
        Counter for total number of regions of missing data
    j : int
        Counter for number regions of missing data not treated by by this
        function
    nan_region : pandas.Series
        Contains information on one region of missing data in col
        count: 
        span:
        start_idx:
        till_idx:
    See choose_fill_method() for info on other parameters.

    Returns
    ----------
    col : pandas.DataFrame
        The column with all nan_regs treated for periods shorter than 1:15.

    ''' # Create a marker column to mark where data has been interpolated
i
j
nan_region
col
col_name
marker_col
nan_regs
one_period
message