Point Subaccessor#
In geotech-pandas, a point represents the point in which a borehole or a soil profile is located.
In this guide, the basics of the point
subaccessor methods are
presented. The point
subaccessor is a collection of point-related
methods intended for managing points in a DataFrame
that contains one or
more points.
First, we import the necessary libraries,
In [1]: import pandas as pd
In [2]: import geotech_pandas
Next, we create a simple DataFrame
with the following data,
In [3]: df = pd.DataFrame(
...: {
...: "point_id": ["BH-1", "BH-1", "BH-1", "BH-2", "BH-2"],
...: "top": [0.0, 1.0, 2.0, 0.0, 1.0],
...: "bottom": [1.0, 2.0, 3.0, 1.0, 5.0],
...: "soil_type": ["sand", "clay", "sand", "sand", "clay"],
...: }
...: )
...:
In [4]: df
Out[4]:
point_id top bottom soil_type
0 BH-1 0.0 1.0 sand
1 BH-1 1.0 2.0 clay
2 BH-1 2.0 3.0 sand
3 BH-2 0.0 1.0 sand
4 BH-2 1.0 5.0 clay
Getting a specific point#
The get_group()
method returns a copy of the supplied
point_id
.
If you somehow forgot the IDs we stored in df
earlier, then you can easliy check the list stored
in the ids
attribute,
In [5]: df.geotech.point.ids
Out[5]: ['BH-1', 'BH-2']
Now, if you wish to get a copy of BH-1,
In [6]: df.geotech.point.get_group("BH-1")
Out[6]:
point_id top bottom soil_type
0 BH-1 0.0 1.0 sand
1 BH-1 1.0 2.0 clay
2 BH-1 2.0 3.0 sand
On the other hand, getting a copy of BH-2,
In [7]: df.geotech.point.get_group("BH-2")
Out[7]:
point_id top bottom soil_type
3 BH-2 0.0 1.0 sand
4 BH-2 1.0 5.0 clay
Note
get_group()
only returns copies of the sliced
DataFrame
, so modifying it will not change anything in the original
DataFrame
.
For example, if we modify the soil type of BH-2 to rock,
In [8]: bh2 = df.geotech.point.get_group("BH-2")
In [9]: bh2.loc[:, "soil_type"] = "rock"
In [10]: bh2
Out[10]:
point_id top bottom soil_type
3 BH-2 0.0 1.0 rock
4 BH-2 1.0 5.0 rock
Then get a new copy of BH-2 from df
,
In [11]: df.geotech.point.get_group("BH-2")
Out[11]:
point_id top bottom soil_type
3 BH-2 0.0 1.0 sand
4 BH-2 1.0 5.0 clay
As you can see, the DataFrame
copy in bh2
was modified, but not
the new copy from the source DataFrame
. This is because of the
Copy-on-Write optimizations in pandas
which prevents modifications on copies to
reflect on the source. Keep this in mind when modifying copies as it may not be the behavior you
want. For more information, see Copy-on-Write (CoW).