Extracting sample depths#

This example merges core section top depth and sample depth to provide depths for individual samples. It does not require paleos at all and is here to serve as an example for those who have a similar challenge.

from pathlib import Path
import pandas as pd

Begin by defining the location of our data

data_path = Path("data")
samples_path = data_path / "samples_biom_730.csv"
depth_path = data_path / "section_summary_730.csv"

Read in the sample data

df_samples = pd.read_csv(samples_path)
df_samples["Hole"] = [x.strip("'") for x in df_samples["Hole"]]
df_samples.loc[df_samples["Section"] == "CC", "Section"] = 20
df_samples["Section"] = df_samples["Section"].astype(int)
print(df_samples)

Out:

   Hole  Core  Section  Top (cm)
0     A     1        4        40
1     A     1        1        13
2     A     2        1        40
3     A     2        4        40
4     A     3        1        40
5     A     3        5        40
6     A     3       20        20
7     A     4        4        40
8     A     5        4        40
9     A     6        4        40
10    A     7        4        40
11    A     8        4        40
12    A     9        1        40
13    A    10        1        40
14    A    11        1        40
15    A    11        5        40
16    A    12        2        40
17    A    12        6        40
18    A    13        3        40
19    A    14        4        40
20    A    14       20        20
21    A    15        4        40
22    A    16        4        40
23    A    16       20        20
24    A    18        1        40
25    A    18        5        40
26    A    19        1        40
27    A    19        5        40
28    A    20        1        40
29    A    20        5        40
30    A    21        2        40
31    A    21        6        40
32    A    22        2        40
33    A    22        6        40
34    A    23        2        40
35    A    23        6        40
36    A    24        2        40
37    A    24        6        40
38    A    25        2        40
39    A    25        6        40
40    A    26        2        40
41    A    26       20        10
42    A    27        4        40
43    A    28        3        40
44    A    29        2        40
45    A    29       20        10
46    A    30        4        40
47    A    31        1        40
48    A    31        5        40
49    A    32        1        40
50    A    33        3        40
51    A    34        1        40
52    A    35        2         8
53    A    37        1        40
54    A    38        1        40

Read in depth data for the core

df_depth = pd.read_csv(depth_path)
df_depth = df_depth.dropna(subset=["Section"])
df_depth.loc[df_depth["Section"].str.contains("CC"), "Section"] = 20
df_depth["Section"] = df_depth["Section"].astype(int)
print(df_depth)

Out:

     Exp  ...                                     Comments
0    117  ...                            (DB) VOID 0-16 CM
1    117  ...                                          NaN
2    117  ...                                          NaN
3    117  ...                                 145-150CM IW
4    117  ...                                          NaN
..   ...  ...                                          ...
267  117  ...                                          NaN
268  117  ...     OG-25CM (115-140CM); IW-10CM (140-150CM)
269  117  ...                                          NaN
270  117  ...                                          NaN
271  117  ...  7CM TO PALEO  (DB) CL CHANGED FROM 44 TO 51

[272 rows x 18 columns]

Use pandas merging to put the two together and get sample depth

df = pd.merge(
    df_samples,
    df_depth,
    how="left",
    left_on=["Hole", "Core", "Section"],
    right_on=["Hole", "Core", "Section"],
)
df["Depth"] = df["Top depth CSF-A (m)"] + (df["Top (cm)"]/100)
df.to_csv("samples_with_depth.csv", index=False)
print(df)

Out:

   Hole  Core  ...                                     Comments   Depth
0     A     1  ...                                 145-150CM IW    4.90
1     A     1  ...                            (DB) VOID 0-16 CM    0.13
2     A     2  ...                                          NaN    8.70
3     A     2  ...                                          NaN   13.20
4     A     3  ...                                          NaN   18.20
5     A     3  ...                                          NaN   24.20
6     A     3  ...                                5 CM TO PALEO   27.52
7     A     4  ...                                          NaN   32.20
8     A     5  ...                                          NaN   41.70
9     A     6  ...                 OG AT 120-145; IW AT 145-150   51.20
10    A     7  ...                                          NaN   60.70
11    A     8  ...                                          NaN   70.40
12    A     9  ...                                          NaN   75.60
13    A    10  ...                                          NaN   85.30
14    A    11  ...                                          NaN   95.00
15    A    11  ...                                          NaN  101.00
16    A    12  ...                                          NaN  106.10
17    A    12  ...                                          NaN  112.10
18    A    13  ...                                          NaN  117.30
19    A    14  ...                                          NaN  128.40
20    A    14  ...                                5 CM TO PALEO  133.08
21    A    15  ...                 OG AT 120-145; IW AT 145-150  138.10
22    A    16  ...                                          NaN  147.80
23    A    16  ...                                5 CM TO PALEO  152.42
24    A    18  ...                                          NaN  162.60
25    A    18  ...                                          NaN  168.60
26    A    19  ...                                          NaN  172.30
27    A    19  ...                                          NaN  178.30
28    A    20  ...                                          NaN  182.00
29    A    20  ...                                          NaN  188.00
30    A    21  ...                                          NaN  193.10
31    A    21  ...                                          NaN  199.10
32    A    22  ...                                          NaN  202.80
33    A    22  ...                                          NaN  208.80
34    A    23  ...                                          NaN  212.50
35    A    23  ...                                          NaN  218.50
36    A    24  ...                                          NaN  222.10
37    A    24  ...                                          NaN  228.10
38    A    25  ...                                          NaN  231.80
39    A    25  ...                                          NaN  237.80
40    A    26  ...                                          NaN  241.50
41    A    26  ...                                5 CM TO PALEO  246.73
42    A    27  ...                                          NaN  254.10
43    A    28  ...                                          NaN  262.30
44    A    29  ...                                          NaN  270.50
45    A    29  ...                                5 CM TO PALEO  275.44
46    A    30  ...                                          NaN  283.10
47    A    31  ...                                          NaN  288.30
48    A    31  ...                                          NaN  294.30
49    A    32  ...                                          NaN  298.00
50    A    33  ...  (DB)CHANGED OG TO 115-140 & IW TO 140-150CM  310.60
51    A    34  ...                                          NaN  317.30
52    A    35  ...                                          NaN  328.18
53    A    37  ...                                          NaN  346.30
54    A    38  ...                                          NaN  356.00

[55 rows x 20 columns]

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

Gallery generated by Sphinx-Gallery