Question: def what _ year _ debug ( fraction = 0 . 5 , source = 'Both' ) : # Calculate cumulative sums of emissions by

def what_year_debug(fraction=0.5, source='Both'):
# Calculate cumulative sums of emissions by year for each source
df_emissions['Cumulative_Fossil']= df_emissions[['Coal', 'Oil', 'Gas', 'Cement', 'Flaring', 'Other']].sum(axis=1).cumsum()
df_emissions['Cumulative_Land']= df_emissions['Land'].cumsum()
df_emissions['Cumulative_Both']= df_emissions['Cumulative_Fossil']+ df_emissions['Cumulative_Land']
# Get the total cumulative emissions for the specified source
total_emissions = df_emissions[f'Cumulative_{source}'].iloc[-1]
# Find the year where the cumulative emissions exceed the fraction of interest
target_emissions = total_emissions * fraction
year_row = df_emissions[df_emissions[f'Cumulative_{source}']>= target_emissions].iloc[0]
# Return the year as an integer
return int(year_row['Year'])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!