vendredi 2 avril 2021

How i can recognize a NaN value in a conditional?

I have two data frames, each one with a diferent method to detect anomalies (Grubbs and MAD) and the data frame has NaN when the method detect it was a anomalie, so i have two data frames, with NaN, when the method sed it was anomalie, and i need to compare this two dataframes and when de value is NaN for both methods keep de NaN an when is for one methot anomalie an for the other one is not, let the number.

so i have try these, im just learning to use python, and maybe i dont know how to recognice a NaN value

Blockquote

`def anomalos(anomalos_MAD, anomalos_GRUBBS, df):
cod_est = list(pd.unique(df['Codigo']))
lista_sin_anomalos = []
# MADS

for est in cod_est[0:1]:
    print('Leyendo la estacion:', est)
    # Filtramos por estacion
    # Leyendo el df de anomalos generado con MAD

    datosMAD = anomalos_MAD[anomalos_MAD['Codigo'] == est]
    datosMAD = datosMAD.iloc[:, 0:12]
    print(datosMAD.to_string())

    # Leyendo el df de anomalos generado con GRUBBS
    datosGRUBBS = anomalos_GRUBBS[anomalos_GRUBBS['Codigo'] == est]
    datosGRUBBS = datosGRUBBS.iloc[:, 0:12]
    print(datosGRUBBS.to_string())

    # Leyendo el df ORIGINAL
    datos = df[df['Codigo'] == est]
    datos = datos.iloc[:, 0:12]
    print(datos.to_string())

    if (datosGRUBBS[datosGRUBBS.iloc[:, 0:12]] and datosMAD[datosMAD[:, 0:12]]) == 'NaN':
        lista_sin_anomalos = np.nan
        print(lista_sin_anomalos)

    else:
        lista_sin_anomalos = datos

Aucun commentaire:

Enregistrer un commentaire