src/ei_mcoe/ei_mcoe.py
def clean_part2_output(part2_df, separate_nems_cols=False):
    """Clean output for Part 2: select columns, choose NEMS column type, round.

    Args:
        part2_df (pandas.DataFrame): The output from running bulid_part2_
            output().
        separate_nems_cols (boolean): An indication of whether to include the
            NEMS cost columns alongside the FERC Form 1 cost columns for fixed
            and variable cost or keep the NEMS columns as boolean flag columns
            with True is NEMS is used and merged into a common fixed or
            variable column.

    Returns:
        pandas.DataFrame: A DataFrame with all of the components of Part 2,
            cleaned and ready for output.
    """
    logger.info('Cleaning Part 2 output')
    # Select output columns
    # Show per mwh values for fixed and variable cost
    mask = (part2_df.fixed_v_total_ratio.isnull() &
            (part2_df.fuel_type_code_pudl == 'coal'))
    logger.info(
        f"inserting 80% fixed/var ratio for {len(part2_df[mask])} records")
    part2_df.loc[mask, 'fixed_v_total_ratio'] = .811
    part2_df.loc[mask, 'var_v_total_ratio'] = .188

    part2_df = part2_df.assign(
        fixed_om=lambda x: x.fix_var_om * x.fixed_v_total_ratio,
        variable_om=lambda x: x.fix_var_om * x.var_v_total_ratio,
        fixed_om_mwh=lambda x: x.fixed_om / x.net_generation_mwh_ferc1,
        fixed_om_mw=lambda x: x.fixed_om / x.capacity_mw,
        variable_om_mwh=lambda x: x.variable_om / x.net_generation_mwh_ferc1,
        fix_var_om_mwh_19_nems=lambda x:
            x.fixed_om_mwh_19_nems + x.variable_om_mwh_19_nems,
        net_generation_mwh_eia=lambda x: x.net_generation_mwh,
        net_generation_mwh_source=lambda x:
            np.where(
                x.net_generation_mwh_eia.notnull(),
                'eia',
                np.where(
                    x.net_generation_mwh_ferc1.notnull(),
                    'ferc1',
                    np.where(
                        x.net_generation_mwh_nems.notnull(),
                        'nems',
                        pd.NA
                    )
                )
            ),
        net_generation_mwh=lambda x:
            x.net_generation_mwh.fillna(
                x.net_generation_mwh_ferc1.fillna(
                    x.net_generation_mwh_nems))
    )
    # Combine NEMS and FERC1 cost columns; create bool column to show NEMS use.
    if separate_nems_cols:
        part2_df = (
            part2_df.assign(
                # capacity_mw_eia_v_nems_diff_rate=lambda x:
                #    (x.capacity_mw / x.capacity_mw_nems).fillna(1),
                fix_var_ferc1_v_nems_diff_rate=lambda x:
                    (x.fix_var_om_mwh / x.fix_var_om_mwh_19_nems).fillna(1),
                fix_var_is_NEMS=lambda x: (
                    x.fix_var_om_mwh.isna() &
                    x.fix_var_om_mwh_19_nems.notna()),
                fix_var_om_mwh=lambda x: np.where(
                    x.fix_var_ferc1_v_nems_diff_rate.between(.1, 10),
                    x.fix_var_om_mwh.fillna(x.fix_var_om_mwh_19_nems),
                    x.fix_var_om_mwh_19_nems,),
                variable_om_mwh=lambda x: np.where(
                    x.fix_var_ferc1_v_nems_diff_rate.between(.1, 10),
                    x.variable_om_mwh.fillna(x.variable_om_mwh_19_nems),
                    x.variable_om_mwh_19_nems,),
                fixed_om_mwh=lambda x: np.where(
                    x.fix_var_ferc1_v_nems_diff_rate.between(.1, 10),
                    x.fixed_om_mwh.fillna(x.fixed_om_mwh_19_nems),
                    x.fixed_om_mwh_19_nems),
            )
        )
    part2_df['ferc1_unit_count'] = part2_df['ferc1_unit_count'].astype('Int64')
    # Calculate MCOE value
    logger.info('Calculate MCOE.')
    part2_df = part2_df.assign(
        mcoe=lambda x: x.fuel_cost_mwh_eia923 + x.fix_var_om_mwh)
    logger.info('Finished cleaning Part 2 data')
    return part2_df
Clean output for Part 2: select columns, choose NEMS column type, round.

    Args:
        part2_df (pandas.DataFrame): The output from running bulid_part2_
            output().
        separate_nems_cols (boolean): An indication of whether to include the
            NEMS cost columns alongside the FERC Form 1 cost columns for fixed
            and variable cost or keep the NEMS columns as boolean flag columns
            with True is NEMS is used and merged into a common fixed or
            variable column.

    Returns:
        pandas.DataFrame: A DataFrame with all of the components of Part 2,
            cleaned and ready for output.
    
Clean output for Part 2: select columns, choose NEMS column type, round.
Clean output for Part 2 : select columns choose NEMS column type round .
def clean_part2_output(part2_df, separate_nems_cols=False):
    logger.info('Cleaning Part 2 output')
    mask = (part2_df.fixed_v_total_ratio.isnull() &
            (part2_df.fuel_type_code_pudl == 'coal'))
    logger.info(
        f"inserting 80% fixed/var ratio for {len(part2_df[mask])} records")
    part2_df.loc[mask, 'fixed_v_total_ratio'] = .811
    part2_df.loc[mask, 'var_v_total_ratio'] = .188
    part2_df = part2_df.assign(
        fixed_om=lambda x: x.fix_var_om * x.fixed_v_total_ratio,
        variable_om=lambda x: x.fix_var_om * x.var_v_total_ratio,
        fixed_om_mwh=lambda x: x.fixed_om / x.net_generation_mwh_ferc1,
        fixed_om_mw=lambda x: x.fixed_om / x.capacity_mw,
        variable_om_mwh=lambda x: x.variable_om / x.net_generation_mwh_ferc1,
        fix_var_om_mwh_19_nems=lambda x:
            x.fixed_om_mwh_19_nems + x.variable_om_mwh_19_nems,
        net_generation_mwh_eia=lambda x: x.net_generation_mwh,
        net_generation_mwh_source=lambda x:
            np.where(
                x.net_generation_mwh_eia.notnull(),
                'eia',
                np.where(
                    x.net_generation_mwh_ferc1.notnull(),
                    'ferc1',
                    np.where(
                        x.net_generation_mwh_nems.notnull(),
                        'nems',
                        pd.NA
                    )
                )
            ),
        net_generation_mwh=lambda x:
            x.net_generation_mwh.fillna(
                x.net_generation_mwh_ferc1.fillna(
                    x.net_generation_mwh_nems))
    )
    if separate_nems_cols:
        part2_df = (
            part2_df.assign(
                fix_var_ferc1_v_nems_diff_rate=lambda x:
                    (x.fix_var_om_mwh / x.fix_var_om_mwh_19_nems).fillna(1),
                fix_var_is_NEMS=lambda x: (
                    x.fix_var_om_mwh.isna() &
                    x.fix_var_om_mwh_19_nems.notna()),
                fix_var_om_mwh=lambda x: np.where(
                    x.fix_var_ferc1_v_nems_diff_rate.between(.1, 10),
                    x.fix_var_om_mwh.fillna(x.fix_var_om_mwh_19_nems),
                    x.fix_var_om_mwh_19_nems,),
                variable_om_mwh=lambda x: np.where(
                    x.fix_var_ferc1_v_nems_diff_rate.between(.1, 10),
                    x.variable_om_mwh.fillna(x.variable_om_mwh_19_nems),
                    x.variable_om_mwh_19_nems,),
                fixed_om_mwh=lambda x: np.where(
                    x.fix_var_ferc1_v_nems_diff_rate.between(.1, 10),
                    x.fixed_om_mwh.fillna(x.fixed_om_mwh_19_nems),
                    x.fixed_om_mwh_19_nems),
            )
        )
    part2_df['ferc1_unit_count'] = part2_df['ferc1_unit_count'].astype('Int64')
    logger.info('Calculate MCOE.')
    part2_df = part2_df.assign(
        mcoe=lambda x: x.fuel_cost_mwh_eia923 + x.fix_var_om_mwh)
    logger.info('Finished cleaning Part 2 data')
    return part2_df
def clean_part2_output ( part2_df , separate_nems_cols = False ) : logger . info ( 'Cleaning Part 2 output' ) mask = ( part2_df . fixed_v_total_ratio . isnull ( ) & ( part2_df . fuel_type_code_pudl == 'coal' ) ) logger . info ( f"inserting 80% fixed/var ratio for {len(part2_df[mask])} records" ) part2_df . loc [ mask , 'fixed_v_total_ratio' ] = .811 part2_df . loc [ mask , 'var_v_total_ratio' ] = .188 part2_df = part2_df . assign ( fixed_om = lambda x : x . fix_var_om * x . fixed_v_total_ratio , variable_om = lambda x : x . fix_var_om * x . var_v_total_ratio , fixed_om_mwh = lambda x : x . fixed_om / x . net_generation_mwh_ferc1 , fixed_om_mw = lambda x : x . fixed_om / x . capacity_mw , variable_om_mwh = lambda x : x . variable_om / x . net_generation_mwh_ferc1 , fix_var_om_mwh_19_nems = lambda x : x . fixed_om_mwh_19_nems + x . variable_om_mwh_19_nems , net_generation_mwh_eia = lambda x : x . net_generation_mwh , net_generation_mwh_source = lambda x : np . where ( x . net_generation_mwh_eia . notnull ( ) , 'eia' , np . where ( x . net_generation_mwh_ferc1 . notnull ( ) , 'ferc1' , np . where ( x . net_generation_mwh_nems . notnull ( ) , 'nems' , pd . NA ) ) ) , net_generation_mwh = lambda x : x . net_generation_mwh . fillna ( x . net_generation_mwh_ferc1 . fillna ( x . net_generation_mwh_nems ) ) ) if separate_nems_cols : part2_df = ( part2_df . assign ( fix_var_ferc1_v_nems_diff_rate = lambda x : ( x . fix_var_om_mwh / x . fix_var_om_mwh_19_nems ) . fillna ( 1 ) , fix_var_is_NEMS = lambda x : ( x . fix_var_om_mwh . isna ( ) & x . fix_var_om_mwh_19_nems . notna ( ) ) , fix_var_om_mwh = lambda x : np . where ( x . fix_var_ferc1_v_nems_diff_rate . between ( .1 , 10 ) , x . fix_var_om_mwh . fillna ( x . fix_var_om_mwh_19_nems ) , x . fix_var_om_mwh_19_nems , ) , variable_om_mwh = lambda x : np . where ( x . fix_var_ferc1_v_nems_diff_rate . between ( .1 , 10 ) , x . variable_om_mwh . fillna ( x . variable_om_mwh_19_nems ) , x . variable_om_mwh_19_nems , ) , fixed_om_mwh = lambda x : np . where ( x . fix_var_ferc1_v_nems_diff_rate . between ( .1 , 10 ) , x . fixed_om_mwh . fillna ( x . fixed_om_mwh_19_nems ) , x . fixed_om_mwh_19_nems ) , ) ) part2_df [ 'ferc1_unit_count' ] = part2_df [ 'ferc1_unit_count' ] . astype ( 'Int64' ) logger . info ( 'Calculate MCOE.' ) part2_df = part2_df . assign ( mcoe = lambda x : x . fuel_cost_mwh_eia923 + x . fix_var_om_mwh ) logger . info ( 'Finished cleaning Part 2 data' ) return part2_df
Clean output for Part 2: select columns, choose NEMS column type, round.
Clean output for Part 2 : select columns choose NEMS column type round .
"""Clean output for Part 2: select columns, choose NEMS column type, round.

    Args:
        part2_df (pandas.DataFrame): The output from running bulid_part2_
            output().
        separate_nems_cols (boolean): An indication of whether to include the
            NEMS cost columns alongside the FERC Form 1 cost columns for fixed
            and variable cost or keep the NEMS columns as boolean flag columns
            with True is NEMS is used and merged into a common fixed or
            variable column.

    Returns:
        pandas.DataFrame: A DataFrame with all of the components of Part 2,
            cleaned and ready for output.
    """ # Select output columns # Show per mwh values for fixed and variable cost # Combine NEMS and FERC1 cost columns; create bool column to show NEMS use. # capacity_mw_eia_v_nems_diff_rate=lambda x: #    (x.capacity_mw / x.capacity_mw_nems).fillna(1), # Calculate MCOE value
A DataFrame with all of the components of Part 2,
cleaned and ready for output.
A DataFrame with all of the components of Part 2 cleaned and ready for output .
pandas.DataFrame
part2_df
The output from running bulid_part2_
output().
The output from running bulid_part2_ output () .
separate_nems_cols
An indication of whether to include the
NEMS cost columns alongside the FERC Form 1 cost columns for fixed
and variable cost or keep the NEMS columns as boolean flag columns
with True is NEMS is used and merged into a common fixed or
variable column.
An indication of whether to include the NEMS cost columns alongside the FERC Form 1 cost columns for fixed and variable cost or keep the NEMS columns as boolean flag columns with True is NEMS is used and merged into a common fixed or variable column .