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
| # List of columns to process with their respective bounds
columns_of_interest = [
(('A', 'Y1'), df_A['SPECVMIN'].iloc[0], df_A['SPECVMAX'].iloc[0]),
(('B', 'Y1'), df_B['SPECVMIN'].iloc[0], df_B['SPECVMAX'].iloc[0]),
(('C', 'Y1'), df_C['SPECVMIN'].iloc[0], df_C['SPECVMAX'].iloc[0]),
(('D', 'Y2'), df_D['SPECVMIN'].iloc[0], df_D['SPECVMAX'].iloc[0]),
(('E', 'Y2'), df_E['SPECVMIN'].iloc[0], df_E['SPECVMAX'].iloc[0]),
(('F', 'Y2'), df_F['SPECVMIN'].iloc[0], df_F['SPECVMAX'].iloc[0]),
]
# Initialize empty DataFrames to store results
results_prc_list = []
# Iterate over columns
for (col_name, measure_name), min_bound, max_bound in columns_of_interest:
df1_column = df1[(col_name, measure_name)].copy().to_frame()
# Create conditions for each category
if measure_name == 'g':
condition_nok = (df1_column < min_bound - 0.0049) | (df1_column > max_bound + 0.0049)
condition_ok = (df1_column > min_bound) & (df1_column < max_bound)
condition_limit = ((df1_column >= min_bound-0.0049) & (df1_column < min_bound)) | ((df1_column >= max_bound) & (df1_column <= max_bound + 0.0049))
else:
condition_nok = (df1_column < min_bound - 0.49) | (df1_column > max_bound + 0.49)
condition_ok = (df1_column > min_bound) & (df1_column < max_bound)
condition_limit = ((df1_column >= min_bound-0.49) & (df1_column < min_bound)) | ((df1_column >= max_bound) & (df1_column <= max_bound + 0.49))
# Assign categories based on conditions using NumPy indexing
categories = ['NOK', 'OK', 'Limit']
conditions = [condition_nok, condition_ok, condition_limit]
df1[f'Type_de_point_{measure_name}'] = np.select(conditions, categories, default='NOK') |
Partager