Create Sample

The base object is a Sample, so let’s create one

import pandas as pd
from elphick.geomet.utils.data import sample_data
from elphick.geomet import Sample

Load Data

First, let’s load some toy data. For demonstration this toy data has mixed case column names.

df: pd.DataFrame = sample_data(include_moisture=False)
df
wet_mass mass_dry FE SIO2 al2o3 LOI group
index
0 100.0 90.0 57.0 5.2 3.0 5.0 grp_1
1 90.0 80.0 59.0 3.1 1.7 4.0 grp_1
2 110.0 90.0 61.0 2.2 0.9 3.0 grp_2


Create Sample

The Sample object has a data attribute that is a pandas DataFrame. Where column names are recognised as components the case is converted to the represent the chemical symbols.

sample: Sample = Sample(data=df, name='sample')
sample.data
2024-10-03 13:39:16,740 - INFO - Elapsed time for data: 0:00:00.120160
2024-10-03 13:39:16,769 - INFO - Elapsed time for data: 0:00:00.002380
2024-10-03 13:39:16,774 - INFO - Elapsed time for data: 0:00:00.001795
wet_mass mass_dry H2O Fe SiO2 Al2O3 LOI group
index
0 100.0 90.0 10.000000 57.0 5.2 3.0 5.0 grp_1
1 90.0 80.0 11.111111 59.0 3.1 1.7 4.0 grp_1
2 110.0 90.0 18.181818 61.0 2.2 0.9 3.0 grp_2


Aggregation

The aggregate of the mass-composition is available via the aggregate property of the Sample object.

sample.aggregate
wet_mass mass_dry H2O Fe SiO2 Al2O3 LOI
0 300.0 260.0 13.333333 59.0 3.515385 1.873077 4.0


For aggregation/weight-average by a grouping variable we can use the weight_average method.

sample.weight_average(group_by='group')
wet_mass mass_dry H2O Fe SiO2 Al2O3 LOI
group
grp_1 190.0 170.0 10.526316 57.941176 4.211765 2.388235 4.529412
grp_2 110.0 90.0 18.181818 61.000000 2.200000 0.900000 3.000000


Total running time of the script: (0 minutes 0.213 seconds)

Gallery generated by Sphinx-Gallery