I have a weather dataset, that has the following columns: date, average daily temp, and rain probability. I am trying to find the rage of dates, where the daily temp and rain probability meets certain condition. For instance, let us assume the below dataset..
df = pd.DataFrame({"date": pd.date_range(start='2020-11-01', end='2020-11-10'),
"avg_daily_temp": [35, 40, 25, 28, 23, 22, 25, 28, 30, 28],
"rain_probability": [0.2, 0.1, 0.7, 0.8, 0.6, 0.9, 1.0, 0.5, 0.2, 0.3]})
So, for the dataset above, I have the following requirement: I want to get the range of dates where the avg daily temp is within the range 20 - 29, and the probability of rain is greater than 0.5 for consecutive 4 days. The output shall be a list with range of dates (4 day period) that meet the above requirement. For instance, for the above dataset, the output should be: [['2020-11-03', '2020-11-06'], ['2020-11-04', '2020-11-07']]
Should I iterate through each row to get the four day period, or are there any other better way to perform this operation? I am fine either with python or R..
Thanks in advance..
Siva
question from:
https://stackoverflow.com/questions/65649452/iterate-multiple-rows-to-check-for-condition 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…