@@ -117,7 +117,7 @@ def apply_export_tariff_params(dataframe, net_metering_state_df, net_metering_ut
117117 net_metering_utility_df = net_metering_utility_df [['eia_id' ,'sector_abbr' ,'state_abbr' ]+ nem_columns ]
118118
119119 # check if utility-specific NEM parameters apply to any agents - need to join on state too (e.g. Pacificorp UT vs Pacificorp ID)
120- temp_df = pd .merge (dataframe , net_metering_utility_df , how = 'left' , on = ['eia_id' ,'sector_abbr' ,'state_abbr' ])
120+ temp_df = pd .merge (dataframe , net_metering_utility_df . drop_duplicates () , how = 'left' , on = ['eia_id' ,'sector_abbr' ,'state_abbr' ])
121121
122122 # filter agents with non-null nem_system_kw_limit - these are agents WITH utility NEM
123123 agents_with_utility_nem = temp_df [pd .notnull (temp_df ['nem_system_kw_limit' ])]
@@ -127,7 +127,7 @@ def apply_export_tariff_params(dataframe, net_metering_state_df, net_metering_ut
127127
128128 # merge agents with state-specific NEM parameters
129129 net_metering_state_df = net_metering_state_df [['state_abbr' , 'sector_abbr' ]+ nem_columns ]
130- agents_without_utility_nem = pd .merge (agents_without_utility_nem , net_metering_state_df , how = 'left' , on = ['state_abbr' , 'sector_abbr' ])
130+ agents_without_utility_nem = pd .merge (agents_without_utility_nem , net_metering_state_df . drop_duplicates () , how = 'left' , on = ['state_abbr' , 'sector_abbr' ])
131131
132132 # re-combine agents list and fill nan's
133133 dataframe = pd .concat ([agents_with_utility_nem , agents_without_utility_nem ], sort = False )
@@ -401,11 +401,9 @@ def apply_financial_params(dataframe, financing_terms, itc_options, inflation_ra
401401 '''
402402 dataframe = dataframe .reset_index ()
403403
404- # Merge financing terms onto agent DataFrame
405- dataframe = dataframe .merge (financing_terms , how = 'left' , on = ['year' , 'sector_abbr' ])
404+ dataframe = dataframe .merge (financing_terms .drop_duplicates (), how = 'left' , on = ['year' , 'sector_abbr' ])
406405
407- # Merge ITC options on to DataFrame
408- dataframe = dataframe .merge (itc_options [['itc_fraction_of_capex' , 'year' , 'tech' , 'sector_abbr' ]],
406+ dataframe = dataframe .merge (itc_options [['itc_fraction_of_capex' , 'year' , 'tech' , 'sector_abbr' ]].drop_duplicates (),
409407 how = 'left' , on = ['year' , 'tech' , 'sector_abbr' ])
410408
411409 # Set inflation rate data to 'inflation_rate' column in agent DataFrame
@@ -441,9 +439,7 @@ def apply_load_growth(dataframe, load_growth_df):
441439
442440 # Create 'county_id' column in agent DataFrame
443441 dataframe ["county_id" ] = dataframe .county_id .astype (int )
444-
445- # Merge load growth data onto agent DataFrame
446- dataframe = pd .merge (dataframe , load_growth_df , how = 'left' , on = ['year' , 'sector_abbr' , 'county_id' ])
442+ dataframe = pd .merge (dataframe , load_growth_df .drop_duplicates (), how = 'left' , on = ['year' , 'sector_abbr' , 'county_id' ])
447443
448444 # For residential agents, load growth translates to kwh_per_customer change
449445 dataframe ['load_kwh_per_customer_in_bin' ] = np .where (dataframe ['sector_abbr' ]== 'res' ,
@@ -1049,17 +1045,16 @@ def estimate_initial_market_shares(dataframe, state_starting_capacities_df):
10491045 'developable_agent_weight' , 'developable_customers_in_state' )
10501046 state_total_agents .columns = state_total_agents .columns .str .replace (
10511047 'developable_agent_weight' , 'agent_count' )
1052-
1053- # Merge together
1054- state_denominators = pd .merge (state_total_developable_customers , state_total_agents , how = 'left' , on = [
1048+ # merge together
1049+ state_denominators = pd .merge (state_total_developable_customers , state_total_agents .drop_duplicates (), how = 'left' , on = [
10551050 'state_abbr' , 'sector_abbr' , 'tech' ])
10561051
1057- # Merge back to the main dataframe
1058- dataframe = pd .merge (dataframe , state_denominators , how = 'left' , on = [
1052+ # merge back to the main dataframe
1053+ dataframe = pd .merge (dataframe , state_denominators . drop_duplicates () , how = 'left' , on = [
10591054 'state_abbr' , 'sector_abbr' , 'tech' ])
10601055
1061- # Merge in the state starting capacities
1062- dataframe = pd .merge (dataframe , state_starting_capacities_df , how = 'left' ,
1056+ # merge in the state starting capacities
1057+ dataframe = pd .merge (dataframe , state_starting_capacities_df . drop_duplicates () , how = 'left' ,
10631058 on = ['state_abbr' , 'sector_abbr' ])
10641059
10651060
0 commit comments