Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions