src/ei_mcoe/ei_mcoe.py
def build_part1_output(raw_eia_df, level):
    """Create final data output for Part 1.

    This function compiles information at the plant-fuel or unit-fuel level
    and either sums or finds the weighted average of the aggregated columns.
    Sum applies to 'total_fuel_cost', 'net_generation_mwh', 'capacity_mw', and
    'total_mmbtu'. Weighted average applies to generator age and heat rate.

    Args:
        raw_eia_df (pandas.DataFrame): A DataFrame containing EIA data from the
            pudl_out.mcoe() function that has been run through the prep_raw_
            eia() function.
        level (str): An string indicating the level of desired aggregation.
            Either 'plant-fuel' or 'unit-fuel' are acceptable.

    Returns:
        pandas.DataFrame: A DataFrame that either reflects the plant level
            or unit level EIA data separated by fuel type.
    """
    logger.info('Building Part 1 output')
    # Data validation and heads up
    check_agg_for_diff(raw_eia_df, input_dict['merge_cols_qual'], level)
    agg_df = (
        raw_eia_df.assign(count='place_holder')
        .sort_values(['plant_name_eia', 'state', 'city', 'county',
                      'latitude', 'longitude'])
        .groupby(input_dict[level + '_index_cols'], as_index=False)
        # Must use .join because x.unique() arrays are not hashable
        .agg({'generator_id': lambda x: '; '.join(x.unique()),
              'energy_source_code_1': lambda x: '; '.join(x.unique()),
              'count': lambda x: x.count(),
              'total_fuel_cost': lambda x: x.sum(min_count=1),
              'net_generation_mwh': lambda x: x.sum(min_count=1),
              'capacity_mw': lambda x: x.sum(min_count=1),
              'total_mmbtu': lambda x: x.sum(min_count=1),
              'plant_name_eia': lambda x: x.iloc[0],
              'retirement_date': lambda x: calc_agg_retire_date(x, level),
              'state': lambda x: x.iloc[0],
              'city': lambda x: x.iloc[0],
              'county': lambda x: x.iloc[0],
              'latitude': lambda x: x.iloc[0],
              'longitude': lambda x: x.iloc[0],
              'fuel_cost_from_eiaapi': 'any'})
        .pipe(pudl.helpers.convert_cols_dtypes, 'eia')
    )
    wa_df = weighted_average(
        raw_eia_df,
        eia_wa_col_dict,
        input_dict[level + '_index_cols']
    )
    agg_wa_df = (
        pd.merge(agg_df, wa_df, on=input_dict[level + '_index_cols'],
                 how='left')
        .drop_duplicates()
        .reset_index())
    logger.info('Finished compiling Part 1 ' + level + ' level data')
    return agg_wa_df
Create final data output for Part 1.

    This function compiles information at the plant-fuel or unit-fuel level
    and either sums or finds the weighted average of the aggregated columns.
    Sum applies to 'total_fuel_cost', 'net_generation_mwh', 'capacity_mw', and
    'total_mmbtu'. Weighted average applies to generator age and heat rate.

    Args:
        raw_eia_df (pandas.DataFrame): A DataFrame containing EIA data from the
            pudl_out.mcoe() function that has been run through the prep_raw_
            eia() function.
        level (str): An string indicating the level of desired aggregation.
            Either 'plant-fuel' or 'unit-fuel' are acceptable.

    Returns:
        pandas.DataFrame: A DataFrame that either reflects the plant level
            or unit level EIA data separated by fuel type.
    
Create final data output for Part 1.
This function compiles information at the plant-fuel or unit-fuel level
and either sums or finds the weighted average of the aggregated columns.
Create final data output for Part 1 . This function compiles information at the plant - fuel or unit - fuel level and either sums or finds the weighted average of the aggregated columns .
def build_part1_output(raw_eia_df, level):
    logger.info('Building Part 1 output')
    check_agg_for_diff(raw_eia_df, input_dict['merge_cols_qual'], level)
    agg_df = (
        raw_eia_df.assign(count='place_holder')
        .sort_values(['plant_name_eia', 'state', 'city', 'county',
                      'latitude', 'longitude'])
        .groupby(input_dict[level + '_index_cols'], as_index=False)
        .agg({'generator_id': lambda x: '; '.join(x.unique()),
              'energy_source_code_1': lambda x: '; '.join(x.unique()),
              'count': lambda x: x.count(),
              'total_fuel_cost': lambda x: x.sum(min_count=1),
              'net_generation_mwh': lambda x: x.sum(min_count=1),
              'capacity_mw': lambda x: x.sum(min_count=1),
              'total_mmbtu': lambda x: x.sum(min_count=1),
              'plant_name_eia': lambda x: x.iloc[0],
              'retirement_date': lambda x: calc_agg_retire_date(x, level),
              'state': lambda x: x.iloc[0],
              'city': lambda x: x.iloc[0],
              'county': lambda x: x.iloc[0],
              'latitude': lambda x: x.iloc[0],
              'longitude': lambda x: x.iloc[0],
              'fuel_cost_from_eiaapi': 'any'})
        .pipe(pudl.helpers.convert_cols_dtypes, 'eia')
    )
    wa_df = weighted_average(
        raw_eia_df,
        eia_wa_col_dict,
        input_dict[level + '_index_cols']
    )
    agg_wa_df = (
        pd.merge(agg_df, wa_df, on=input_dict[level + '_index_cols'],
                 how='left')
        .drop_duplicates()
        .reset_index())
    logger.info('Finished compiling Part 1 ' + level + ' level data')
    return agg_wa_df
def build_part1_output ( raw_eia_df , level ) : logger . info ( 'Building Part 1 output' ) check_agg_for_diff ( raw_eia_df , input_dict [ 'merge_cols_qual' ] , level ) agg_df = ( raw_eia_df . assign ( count = 'place_holder' ) . sort_values ( [ 'plant_name_eia' , 'state' , 'city' , 'county' , 'latitude' , 'longitude' ] ) . groupby ( input_dict [ level + '_index_cols' ] , as_index = False ) . agg ( { 'generator_id' : lambda x : '; ' . join ( x . unique ( ) ) , 'energy_source_code_1' : lambda x : '; ' . join ( x . unique ( ) ) , 'count' : lambda x : x . count ( ) , 'total_fuel_cost' : lambda x : x . sum ( min_count = 1 ) , 'net_generation_mwh' : lambda x : x . sum ( min_count = 1 ) , 'capacity_mw' : lambda x : x . sum ( min_count = 1 ) , 'total_mmbtu' : lambda x : x . sum ( min_count = 1 ) , 'plant_name_eia' : lambda x : x . iloc [ 0 ] , 'retirement_date' : lambda x : calc_agg_retire_date ( x , level ) , 'state' : lambda x : x . iloc [ 0 ] , 'city' : lambda x : x . iloc [ 0 ] , 'county' : lambda x : x . iloc [ 0 ] , 'latitude' : lambda x : x . iloc [ 0 ] , 'longitude' : lambda x : x . iloc [ 0 ] , 'fuel_cost_from_eiaapi' : 'any' } ) . pipe ( pudl . helpers . convert_cols_dtypes , 'eia' ) ) wa_df = weighted_average ( raw_eia_df , eia_wa_col_dict , input_dict [ level + '_index_cols' ] ) agg_wa_df = ( pd . merge ( agg_df , wa_df , on = input_dict [ level + '_index_cols' ] , how = 'left' ) . drop_duplicates ( ) . reset_index ( ) ) logger . info ( 'Finished compiling Part 1 ' + level + ' level data' ) return agg_wa_df
Create final data output for Part 1.
Create final data output for Part 1 .
"""Create final data output for Part 1.

    This function compiles information at the plant-fuel or unit-fuel level
    and either sums or finds the weighted average of the aggregated columns.
    Sum applies to 'total_fuel_cost', 'net_generation_mwh', 'capacity_mw', and
    'total_mmbtu'. Weighted average applies to generator age and heat rate.

    Args:
        raw_eia_df (pandas.DataFrame): A DataFrame containing EIA data from the
            pudl_out.mcoe() function that has been run through the prep_raw_
            eia() function.
        level (str): An string indicating the level of desired aggregation.
            Either 'plant-fuel' or 'unit-fuel' are acceptable.

    Returns:
        pandas.DataFrame: A DataFrame that either reflects the plant level
            or unit level EIA data separated by fuel type.
    """ # Data validation and heads up # Must use .join because x.unique() arrays are not hashable
A DataFrame that either reflects the plant level
or unit level EIA data separated by fuel type.
A DataFrame that either reflects the plant level or unit level EIA data separated by fuel type .
pandas.DataFrame
raw_eia_df
A DataFrame containing EIA data from the
pudl_out.mcoe() function that has been run through the prep_raw_
eia() function.
A DataFrame containing EIA data from the pudl_out . mcoe () function that has been run through the prep_raw_ eia () function .
level
An string indicating the level of desired aggregation.
Either 'plant-fuel' or 'unit-fuel' are acceptable.
An string indicating the level of desired aggregation . Either ' plant - fuel ' or ' unit - fuel ' are acceptable .