Mel Zeppel

Merging is simple enough with two rows. However with multiple rows, concat is simpler.

Remember to use [], and add axis = 1 to ensure columns are bound.

df = pd.concat([cea_sample_97, cea_b_103, cea_model_only_90, cea_model_MV_sites_102], axis = 1)

--

--

Read in SQL db from the Audit pack:

#Create a SQL connection to our SQLite database

con = sqlite3.connect(‘Audit_Pack_DataAggregation_220705.db’)

cur = con.cursor()

# select one of the tables from the db

df = pd.read_sql_query(‘SELECT * FROM “0-sites_data”;’, con)

# close the connection

con.close()

df

--

--

# join cores & latts & longs for 7 properties

# Note — check if reading data from 30 cm layer or 120 cm layer

for p in range(0, len( property )):

# read in files and correct column headings

cov_df = pd.read_csv(‘C:/Users/MelZeppel/OneDrive — McCosker Contracting Pty Ltd/ML_development/2022_covariates_QGIS/’ + property.iloc[p]…

--

--

# Read in the Mullion FlintPro sqlite db

conn = sqlite3.connect(“Simplified_RothC_DB.sqlite”)

# Create a SQL connection to our SQLite database

con = sqlite3.connect(“Simplified_RothC_DB.sqlite”)

cur = con.cursor()

# select one of the tables from

df = pd.read_sql_query(‘SELECT * FROM soil_inputs;’, con)

# close the connection

con.close()

df

--

--

Column headings and things to be aware of

File 1 — Strata

df = df.rename(columns = {“name”:”strata_name”,

“round.area.name”:”cea”,

“round_name”:”period”,

“area_ha”: “strata_area_ha”,

“round.area.area_ha”:”cea_area_ha”

})

File 6 — core sublayers

df = pd.read_excel( ‘6-core-sublayer-’ + property.iloc[4] + ‘.xlsx’)

df = df.rename(columns {“s6_socl_core_sublayer_carbon_mass”:”sub_lay_carbon_mass”,

“cum_sublayer_carbon_mass”:”cum_sub_lay_carbon_mass”, “stata_name”:”strata_name”})

### Note that sublayers look like 1 &…

--

--

for p in range(0, len(property)):

df = pd.read_excel(‘C:/Python39/Projects2/Audit_pack/Property_Standard_Mass_3000Tha/’ + property.iloc[p] + ‘-auditing/6-core-sublayer.xlsx’)

df.to_excel(‘C:/Python39/Projects2/Audit_pack/Unsplining_T1_3000Tha/6-core-sublayer-’ + property.iloc[p] + ‘.xlsx’)

--

--

# 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’])

--

--