Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

loops - Iterate multiple rows to check for condition

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...