samedi 21 novembre 2020

Shortened conditional if statement

I need to organise my data into blocks of 30. The data starts at 0 and has a maximum of 1500. Aside from manually typing the data range, how would I loop this in an if/else statement? I am using a panda dataframes and not too familiar with loops.

conditions = [
    (df['Alt'] <= 15),
    (df['Alt'] > 30) & (df['Alt'] <= 45),
    (df['Alt'] > 45) & (df['Alt'] <= 75),
    ....
   (df['Alt'] > 1425) & (df['Alt'] <= 1455),
   (df['Alt'] > 1485) & (df['Alt'] <= 1505),
   (df['Alt'] > 1505)
    ]

values = [30, 60, 90, .....  1410, 1440, 1470, 1500, 1500]

Thanks

Aucun commentaire:

Enregistrer un commentaire