src/ei_mcoe/ei_mcoe.py
def calc_inflation(index, base_year, df, cost_col_name):
    """Calculate new cost with inflation depending on index specified.

    This function calculates inflation using two different indexes. First,
    the one used in the NEMS model ('nems') to calculate nominal fixed and
    variable costs of NEMS data (reported in 87$ - equivalent to 1). Second,
    the FRED Consumer Price Index for All Urban Consumers: Fuels and Utilities
    in U.S. City Average ('fred').

    Args:
        index (str): The desired index to use for the inflation calculation
            (either 'nems' or 'fred'). NEMS index coded to only read 2018
            values.
        base_year (int): The $year the cost values are reported in. Important
            for 'fred' calculations.
        df (pandas.DataFrame): The DataFrame containing the column on which
            you'd like to run an inflation calculation.
        cost_col_names (list): The names of the column of values you'd like to
            calculate inflation for.
    Returns:
        pd.DataFrame: The new, inflation adjusted values for a given year under
            the same name as the original column.
    """
    # For use with NEMS fixed and variable cost data. Reported in '87' dollars
    # which are equal to 1 and only used for 2018 data. (Technically 2019, but
    # will report as our NEMS_YEAR)
    if index == 'nems':
        nems_idx = pd.read_excel(
            ei_mcoe.INPUTS_DIR / 'NEMS_GDP_infl.xlsx',
            header=3,
            names=['Year', 'Rate']
        )
        nems_2019 = float(nems_idx.loc[nems_idx['Year'] == 2019].Rate)
        df[cost_col_name] = df[cost_col_name] * nems_2019
        infl_df = df.rename(
            columns={cost_col_name: cost_col_name[:-2] + '19_nems'})
    # For use with public health damages calculation and fixed / variable cost.
    if index == 'fred':
        fred_df = pull_fred_inflation_df()
        fred_dict = dict(zip(fred_df.year, fred_df.value))
        base_val = (
            fred_df.loc[fred_df['year'] == base_year]
            .reset_index()['value'][0])
        infl_df = (
            df.assign(
                nom_val=lambda x: x.report_year.map(fred_dict),
                base_val=base_val,
                pct_chg=lambda x: (x.nom_val - base_val) / base_val,
                infl_cost=lambda x: (
                    x[cost_col_name] + (x[cost_col_name] * x.pct_chg)))
            .drop(cost_col_name, axis=1)
            .rename(columns={'infl_cost': cost_col_name}))
    return infl_df
Calculate new cost with inflation depending on index specified.

    This function calculates inflation using two different indexes. First,
    the one used in the NEMS model ('nems') to calculate nominal fixed and
    variable costs of NEMS data (reported in 87$ - equivalent to 1). Second,
    the FRED Consumer Price Index for All Urban Consumers: Fuels and Utilities
    in U.S. City Average ('fred').

    Args:
        index (str): The desired index to use for the inflation calculation
            (either 'nems' or 'fred'). NEMS index coded to only read 2018
            values.
        base_year (int): The $year the cost values are reported in. Important
            for 'fred' calculations.
        df (pandas.DataFrame): The DataFrame containing the column on which
            you'd like to run an inflation calculation.
        cost_col_names (list): The names of the column of values you'd like to
            calculate inflation for.
    Returns:
        pd.DataFrame: The new, inflation adjusted values for a given year under
            the same name as the original column.
    
Calculate new cost with inflation depending on index specified.
This function calculates inflation using two different indexes. First,
the one used in the NEMS model ('nems') to calculate nominal fixed and
variable costs of NEMS data (reported in 87$ - equivalent to 1). Second,
the FRED Consumer Price Index for All Urban Consumers: Fuels and Utilities
in U.S. City Average ('fred').
Calculate new cost with inflation depending on index specified . This function calculates inflation using two different indexes . First the one used in the NEMS model ( ' nems ' ) to calculate nominal fixed and variable costs of NEMS data ( reported in 87$ - equivalent to 1 ) . Second the FRED Consumer Price Index for All Urban Consumers : Fuels and Utilities in U . S . City Average ( ' fred ' ) .
def calc_inflation(index, base_year, df, cost_col_name):
    if index == 'nems':
        nems_idx = pd.read_excel(
            ei_mcoe.INPUTS_DIR / 'NEMS_GDP_infl.xlsx',
            header=3,
            names=['Year', 'Rate']
        )
        nems_2019 = float(nems_idx.loc[nems_idx['Year'] == 2019].Rate)
        df[cost_col_name] = df[cost_col_name] * nems_2019
        infl_df = df.rename(
            columns={cost_col_name: cost_col_name[:-2] + '19_nems'})
    if index == 'fred':
        fred_df = pull_fred_inflation_df()
        fred_dict = dict(zip(fred_df.year, fred_df.value))
        base_val = (
            fred_df.loc[fred_df['year'] == base_year]
            .reset_index()['value'][0])
        infl_df = (
            df.assign(
                nom_val=lambda x: x.report_year.map(fred_dict),
                base_val=base_val,
                pct_chg=lambda x: (x.nom_val - base_val) / base_val,
                infl_cost=lambda x: (
                    x[cost_col_name] + (x[cost_col_name] * x.pct_chg)))
            .drop(cost_col_name, axis=1)
            .rename(columns={'infl_cost': cost_col_name}))
    return infl_df
def calc_inflation ( index , base_year , df , cost_col_name ) : if index == 'nems' : nems_idx = pd . read_excel ( ei_mcoe . INPUTS_DIR / 'NEMS_GDP_infl.xlsx' , header = 3 , names = [ 'Year' , 'Rate' ] ) nems_2019 = float ( nems_idx . loc [ nems_idx [ 'Year' ] == 2019 ] . Rate ) df [ cost_col_name ] = df [ cost_col_name ] * nems_2019 infl_df = df . rename ( columns = { cost_col_name : cost_col_name [ : - 2 ] + '19_nems' } ) if index == 'fred' : fred_df = pull_fred_inflation_df ( ) fred_dict = dict ( zip ( fred_df . year , fred_df . value ) ) base_val = ( fred_df . loc [ fred_df [ 'year' ] == base_year ] . reset_index ( ) [ 'value' ] [ 0 ] ) infl_df = ( df . assign ( nom_val = lambda x : x . report_year . map ( fred_dict ) , base_val = base_val , pct_chg = lambda x : ( x . nom_val - base_val ) / base_val , infl_cost = lambda x : ( x [ cost_col_name ] + ( x [ cost_col_name ] * x . pct_chg ) ) ) . drop ( cost_col_name , axis = 1 ) . rename ( columns = { 'infl_cost' : cost_col_name } ) ) return infl_df
Calculate new cost with inflation depending on index specified.
Calculate new cost with inflation depending on index specified .
"""Calculate new cost with inflation depending on index specified.

    This function calculates inflation using two different indexes. First,
    the one used in the NEMS model ('nems') to calculate nominal fixed and
    variable costs of NEMS data (reported in 87$ - equivalent to 1). Second,
    the FRED Consumer Price Index for All Urban Consumers: Fuels and Utilities
    in U.S. City Average ('fred').

    Args:
        index (str): The desired index to use for the inflation calculation
            (either 'nems' or 'fred'). NEMS index coded to only read 2018
            values.
        base_year (int): The $year the cost values are reported in. Important
            for 'fred' calculations.
        df (pandas.DataFrame): The DataFrame containing the column on which
            you'd like to run an inflation calculation.
        cost_col_names (list): The names of the column of values you'd like to
            calculate inflation for.
    Returns:
        pd.DataFrame: The new, inflation adjusted values for a given year under
            the same name as the original column.
    """ # For use with NEMS fixed and variable cost data. Reported in '87' dollars # which are equal to 1 and only used for 2018 data. (Technically 2019, but # will report as our NEMS_YEAR) # For use with public health damages calculation and fixed / variable cost.
The new, inflation adjusted values for a given year under
the same name as the original column.
The new inflation adjusted values for a given year under the same name as the original column .
pd.DataFrame
index
The desired index to use for the inflation calculation
(either 'nems' or 'fred'). NEMS index coded to only read 2018
values.
The desired index to use for the inflation calculation ( either ' nems ' or ' fred ' ) . NEMS index coded to only read 2018 values .
base_year
The $year the cost values are reported in. Important
for 'fred' calculations.
The $year the cost values are reported in . Important for ' fred ' calculations .
df
The DataFrame containing the column on which
you'd like to run an inflation calculation.
The DataFrame containing the column on which you ' d like to run an inflation calculation .
cost_col_name
cost_col_names
The names of the column of values you'd like to
calculate inflation for.
The names of the column of values you ' d like to calculate inflation for .