.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/examples/01_getting_started/01_create_sample.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_examples_01_getting_started_01_create_sample.py: Create Sample ============= The base object is a `Sample`, so let's create one .. GENERATED FROM PYTHON SOURCE LINES 7-11 .. code-block:: Python import pandas as pd from elphick.geomet.utils.data import sample_data from elphick.geomet import Sample .. GENERATED FROM PYTHON SOURCE LINES 12-15 Load Data --------- First, let's load some toy data. For demonstration this toy data has mixed case column names. .. GENERATED FROM PYTHON SOURCE LINES 15-19 .. code-block:: Python df: pd.DataFrame = sample_data(include_moisture=False) df .. raw:: html
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


.. GENERATED FROM PYTHON SOURCE LINES 20-24 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. .. GENERATED FROM PYTHON SOURCE LINES 24-28 .. code-block:: Python sample: Sample = Sample(data=df, name='sample') sample.data .. rst-class:: sphx-glr-script-out .. code-block:: none 2025-03-03 00:31:30,286 - DEBUG - Data has been set. 2025-03-03 00:31:30,286 - INFO - Elapsed time for data: 0:00:00.206286 2025-03-03 00:31:30,340 - INFO - Elapsed time for data: 0:00:00.001855 2025-03-03 00:31:30,345 - INFO - Elapsed time for data: 0:00:00.001833 .. raw:: html
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


.. GENERATED FROM PYTHON SOURCE LINES 29-32 Aggregation ----------- The aggregate of the mass-composition is available via the `aggregate` property of the `Sample` object. .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. code-block:: Python sample.aggregate .. raw:: html
wet_mass mass_dry H2O Fe SiO2 Al2O3 LOI
0 300.0 260.0 13.333333 59.0 3.515385 1.873077 4.0


.. GENERATED FROM PYTHON SOURCE LINES 36-37 For aggregation/weight-average by a grouping variable we can use the `weight_average` method. .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: Python sample.weight_average(group_by='group') .. raw:: html
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


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.344 seconds) .. _sphx_glr_download_auto_examples_examples_01_getting_started_01_create_sample.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_create_sample.ipynb <01_create_sample.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_create_sample.py <01_create_sample.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_