mercredi 8 juillet 2020

How to select a row in a dataframe in which one of the cell value is as close as possible to another predefined value

I have a dataframes with many columns. I want the code to select the row in which one of its values is the closest possible to a predefined value. This predefined value is referred to feature B and is equal to 7.35 Example,

    Feature A        Feature B
       0.1              7.05
         1              7.15
       0.7              7.08
       0.9              7.34
       1.1              7.39
        1               7.30

the code should then select the entire row were feature B is equal to 7.34 because is the closest possible to my value. It will never happen that the predefined value is exactly equal to a value in the feature B (so I cannot use if valueFeature B == predefined value) because I have many decimals so I need a way to extract the row with the value of feature B as similar as possible to that predefined value. Thanks

Aucun commentaire:

Enregistrer un commentaire