def find_primary_gen_fuel(df):
    """
    Determine which fuel generated the most electricity at each power plant
    in 2016

    Parameters
    ----------
    df : dataframe
        Dataframe with monthly generation by facility and fuel type

    Returns
    -------
    DataFrame
        Clean dataframe of primary generation fuel at each plant
    """
    # Sum the generation for each plant by fuel across the entire year
    df_fuel = (df.groupby(['plant_id', 'aer_fuel_type_code'], as_index=False)
                 .sum())

    # Find the dataframe index for the fuel with the most gen at each plant
    # Use this to slice the dataframe and return plant code and primary fuel
    primary_fuel_idx = df_fuel.groupby('plant_id')['net_gen_mwh'].idxmax()
    primary_fuel = df_fuel.loc[primary_fuel_idx,
                               ['aer_fuel_type_code', 'plant_id']]

    primary_fuel.rename(columns={'aer_fuel_type_code': 'primary_fuel'},
                        inplace=True)

    return primary_fuel