Bonjour,
Je suis nouveau sur le forum et j'aurais besoin d'aide.
J'ai écrit un code pour itérer sur les colonnes d'intérêt dans un DataFrame et assigner des catégories ('OK', 'Limit', 'NOK') à une colonne nommée en fonction des bornes minimales et maximales spécifiées pour chaque colonne.
Cependant bien qu'il me compte le bon nombre de données totales il ne m'assigne pas le bon nombre de points dans chaque catégorie.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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')
pouvez-vous m'aider?
Merci