Loops creating new columns that increment

# write a loop for the T0 sublayer of each topsoil to have a mass calculated for each 5 cm layer — equally divided across the 30 cm

final_df = []

for i in range(0,6): # inset the rows below

row_15 = df_T0[( df_T0.core_number == 15353 ) & ( df_T0.sublayer_number ==1 )]

row_15[‘5cm_sublayer_number’] = row_15[‘sub_lay_carbon_mass’] / 6

row_15[‘sublayer_number’] = row_15[‘sublayer_number’] + i

row_15[‘T0_layer’] = 1 # filter to only have the top soil

print(f’loop’, i +1 )

# print(row_15)

final_df = row_15.append(final_df)

final_df.sort_values([‘sublayer_number’])

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Melanie Zeppel

Women in AI: Agribusiness winner - 2022 Superstar of STEM 2022-2023 Scopus Sustainability Researcher of the Year - 2019