-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_function.py
More file actions
311 lines (230 loc) · 12.6 KB
/
Copy pathhelper_function.py
File metadata and controls
311 lines (230 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# pH Helper function
def count_specific_ph_columns_with_ranges(df: pd.DataFrame, count_column: str = 'pH_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific pH levels (pH 1 to pH 6) in their names and creates multiple new columns
for the count of these columns.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of pH columns.
Returns:
pd.DataFrame: The DataFrame with the new columns added.
"""
# Generate the list of specific pH levels to look for
specific_ph_levels = [f'pH {i}' for i in range(1, 11)] # Assuming pH levels from 1 to 10
# Identify columns containing any of the specific pH levels in their names
ph_columns = df.columns[df.columns.str.contains('|'.join(specific_ph_levels))]
# Count the number of identified 'ph' columns
df[count_column] = len(ph_columns)
return df
# Inject Helper function
def count_specific_Inject_columns_with_ranges(df: pd.DataFrame, count_column: str = 'Inject_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific Inject levels (Inject 1 to Inject 12) in their names and creates multiple new columns
for the count of these columns.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of Inject columns.
Returns:
pd.DataFrame: The DataFrame with the new columns added.
"""
# Generate the list of specific Inject levels to look for
specific_Inject_levels = [f'Inject {i}' for i in range(1, 13)] # Assuming Inject levels from 1 to 12
# Identify columns containing any of the specific Inject levels in their names
Inject_columns = df.columns[df.columns.str.contains('|'.join(specific_Inject_levels))]
# Count the number of identified 'Inject' columns
df[count_column] = len(Inject_columns)
return df
# Apparence helper function
def count_specific_Apparence_columns(df: pd.DataFrame, count_column: str = 'Apparence_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific Apparence levels (Apparence 1 to Apparence 6) in their names and creates multiple new columns
for the count of these columns.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of Apparence columns.
Returns:
pd.DataFrame: The DataFrame with the new column added.
"""
# List of specific Apparence levels to look for
specific_Apparence_levels = [f'Apparence {i}' for i in range(1, 11)] # Assuming Apparence levels from 1 to 10
# Identify columns containing any of the specific Apparence levels in their names
Apparence_columns = df.columns[df.columns.str.contains('|'.join(specific_Apparence_levels))]
# Count the number of identified 'Apparence' columns
df[count_column] = len(Apparence_columns)
return df
# Apparence_Piston_échelle helper function
def count_specific_Apparence_Piston_échelle_columns(df: pd.DataFrame, count_column: str = 'Apparence_Piston_échelle_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific Apparence levels (Apparence 1 to Apparence 6) in their names and creates multiple new columns
for the count of these columns.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of Apparence columns.
Returns:
pd.DataFrame: The DataFrame with the new column added.
"""
# List of specific Apparence levels to look for
specific_Apparence_levels = [f'Apparence Piston-échelle {i}' for i in range(1, 13)] # Assuming Apparence Piston-échelle levels from 1 to 12
# Identify columns containing any of the specific Apparence levels in their names
Apparence_columns = df.columns[df.columns.str.contains('|'.join(specific_Apparence_levels))]
# Count the number of identified 'Apparence' columns
df[count_column] = len(Apparence_columns)
return df
# Lido helper function
def count_specific_Lido_columns_with_ranges(df: pd.DataFrame, count_column: str = 'Lido_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific Lido levels (Lido 1 to Lido 20) in their names and creates multiple new columns
for the count of these columns, and the count of columns with values within and outside the range [0.20, 0.35]
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of Lido columns.
Returns:
pd.DataFrame: The DataFrame with the new columns added.
"""
# List of specific Lido levels to look for
specific_Lido_levels = [f'Lido {i}' for i in range(1, 21)] # Assuming Lido levels from 1 to 20
# Identify columns containing any of the specific Lido levels in their names
Lido_columns = df.columns[df.columns.str.contains('|'.join(specific_Lido_levels))]
# Count the number of identified 'Lido' columns
df[count_column] = len(Lido_columns)
return df
# DMA helper function
def count_specific_DMA_columns(df: pd.DataFrame, count_column: str = 'DMA_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific DMA levels in their names and creates multiple new columns
for the count of these columns.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of DMA columns.
Returns:
pd.DataFrame: The DataFrame with the new column added.
"""
# List of specific DMA levels to look for
specific_DMA_levels = [f'DMA {i}' for i in range(1, 11)] # Assuming DMA levels from 1 to 11
# Identify columns containing any of the specific DMA levels in their names
DMA_columns = df.columns[df.columns.str.contains('|'.join(specific_DMA_levels))]
# Count the number of identified 'DMA' columns
df[count_column] = len(DMA_columns)
return df
# LQAS helper function
def count_specific_LQAS_columns(df: pd.DataFrame, count_column: str = 'LQAS_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific LQAS levels (LQAS 1 to LQAS 6) in their names and creates multiple new columns
for the count of these columns.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of LQAS columns.
Returns:
pd.DataFrame: The DataFrame with the new column added.
"""
# List of specific LQAS levels to look for
specific_LQAS_levels = [f'LQAS {i}' for i in range(1, 11)]
# Identify columns containing any of the specific LQAS levels in their names
LQAS_columns = df.columns[df.columns.str.contains('|'.join(specific_LQAS_levels))]
# Count the number of identified 'LQAS' columns
df[count_column] = len(LQAS_columns)
return df
# NaHa/mg/ml helper function
def count_specific_NaHAml_columns_with_ranges(df: pd.DataFrame, count_column: str = 'NaHAml_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific NaHA mg/ml levels in their names and creates multiple new columns
for the count of these columns.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of NaHA/ml columns.
Returns:
pd.DataFrame: The DataFrame with the new columns added.
"""
# List of specific NaHA mg/ml levels to look for
specific_NaHAml_levels = [f'NaHA_ml {i}' for i in range(1, 11)]
# Identify columns containing any of the specific NaHA_ml levels in their names
NaHAml_columns = df.columns[df.columns.str.contains('|'.join(specific_NaHAml_levels))]
# Count the number of identified 'NaHA/ml' columns
df[count_column] = len(NaHAml_columns)
return df
# NaHa/mg/g helper function
def count_specific_NaHA_mg_g_columns_with_ranges(df: pd.DataFrame, count_column: str = 'NaHA_mg_g_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific NaHA_mg_g levels in their names and creates multiple new columns
for the count of these columns.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of NaHA_mg_g columns.
Returns:
pd.DataFrame: The DataFrame with the new columns added.
"""
# List of specific NaHA_mg_g levels to look for
specific_NaHA_mg_g_levels = [f'NaHA_g {i}' for i in range(1, 11)]
# Identify columns containing any of the specific NaHA_mg_g levels in their names
NaHA_mg_g_columns = df.columns[df.columns.str.contains('|'.join(specific_NaHA_mg_g_levels))]
# Count the number of identified 'NaHA_mg_g' columns
df[count_column] = len(NaHA_mg_g_columns)
return df
def count_specific_CaHAP_columns(df: pd.DataFrame, count_column: str = 'CaHAP_Quant_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific CaHAP Quantity levels in their names
and creates a new column with this count.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of CaHAP Quant columns.
Returns:
pd.DataFrame: The DataFrame with the new column added.
"""
# List of specific CaHAP Quant levels to look for
specific_CaHAP_Quant_levels = [f'CaHAP_Q_{i}' for i in range(1, 13)] # Updated to include levels 1 to 12
# Identify columns containing any of the specific CaHAP_Quant levels in their names
CaHAP_Quant_columns = df.columns[df.columns.str.contains('|'.join(specific_CaHAP_Quant_levels))]
# Count the number of identified 'CaHAP_Quant' columns (expected to be 10 as per your requirement)
df[count_column] = len(CaHAP_Quant_columns)
return df
# Rheo helper function
def count_specific_Rheo_columns(df: pd.DataFrame, count_column: str = 'Rheo_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific Rheo levels.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of Rheo levels columns.
Returns:
pd.DataFrame: The DataFrame with the new columns added.
"""
# Generate the list of specific Rhéo levels to look for
specific_rhéo_levels = [f'Rhéo_{i}' for i in range(1, 20)]
# Identify columns containing any of the specific Rhéo levels in their names
rhéo_columns = df.columns[df.columns.str.contains('|'.join(specific_rhéo_levels))]
# Count the number of identified 'Rhéo_' columns
df[count_column] = len(rhéo_columns)
return df
# Osmo helper function
def count_specific_Osmo_columns(df: pd.DataFrame, count_column: str = 'Osmo_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific Osmo levels.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of Osmo levels columns.
Returns:
pd.DataFrame: The DataFrame with the new columns added.
"""
# Generate the list of specific Osmo levels to look for
specific_osmo_levels = [f'Osmo {i}' for i in range(1, 11)]
# Identify columns containing any of the specific Osmo levels in their names
osmo_columns = df.columns[df.columns.str.contains('|'.join(specific_osmo_levels))]
# Count the number of identified 'Osmo' columns
df[count_column] = len(osmo_columns)
return df
# CaHAP Ident helper function
def count_specific_CaHAP_Ident_columns(df: pd.DataFrame, count_column: str = 'CaHAP_Ident_samplesize_count') -> pd.DataFrame:
"""
Counts the number of columns that match specific CaHAP_Ident levels.
Parameters:
df (pd.DataFrame): The DataFrame to process.
count_column (str): The name of the new column to store the count of Osmo levels columns.
Returns:
pd.DataFrame: The DataFrame with the new columns added.
"""
# Generate the list of specific CaHAP_Ident levels to look for
specific_CaHAP_Ident_levels = [f'CaHAP Ident. {i}' for i in range(1, 11)]
# Identify columns containing any of the specific CaHAP Ident. levels in their names
CaHAP_Ident_columns = df.columns[df.columns.str.contains('|'.join(specific_CaHAP_Ident_levels))]
# Count the number of identified 'CaHAP Ident.' columns
df[count_column] = len(CaHAP_Ident_columns)
return df