lundi 5 août 2019

How to combine for loop through rows and if statement

I know it might be really basic, but I can't seem to get it right... I have a dataframe with 4 columns indexed by a timestamp. I would like to loop through each row and, if a value of a certain row is beyond limits, print both the timestamp, column name and value. How do I iterate within applying the filter?

Values are all floats and have been trying with iterrows and iteritems.

inf_value = -5
sup_value = 200

for index, row in df.iterrows():
   if row > sup_value:
      print(index, df.column, value)
   if row < inf_value:
      print(index, df.column, value)

I would expect it to print the timestamp followed by the column name and value such as: 05/08/2019 Column1 205.5

Any help?

Aucun commentaire:

Enregistrer un commentaire