# How to select only the last hour of weather data from each week in R?

I have a weather dataset with observations collected at 15-minute intervals for several weeks. I would like to extract only the last hour of weather data for each week and disregard the rest. In the week 15for example, I only want to keep rows from the cell 147 to 150 (last four rows – each… Read More How to select only the last hour of weather data from each week in R?

# How to select a certain period based on a condition in R?

I have conducted several experiments that lasted for about a week. For each week, I’d like keep periods/rows when precipitation began to the end of the week. I know how to discard dry weeks, but I’m not sure how to select periods from the beginning of rain until the end of wet weeks. My data… Read More How to select a certain period based on a condition in R?

# Pandas histogram of number of occurences of other columns after groupby

I have a dataframe: df = Batch_ID DateTime Code A1 A2 ABC. ‘2019-01-02 17:03:41.000’ 230 2. 4 ABC. ‘2019-01-02 17:03:42.000’ 231 1. 4 ABC. ‘2019-01-02 17:03:48.000’ 232 2. 7 ABC. ‘2019-01-02 17:04:41.000’ 230 2. 9 ABB. ‘2019-01-02 17:04:41.000’ 235 5. 4 ABB. ‘2019-01-02 17:04:45.000’ 236 2. 0 I need to generate an plot of an… Read More Pandas histogram of number of occurences of other columns after groupby

# pandas how to get sorted value in groupby object

I have a dataframe df = Col Val a. 8 a. 9 c. 4 c. 0 d. 3 d. 9 I want to sort by Val of the smallest value within group and then foreach row get the index of the groupby Col So the new df will df df_new = Col Val Idx c.… Read More pandas how to get sorted value in groupby object

# pandas get time delta between two conditions per group

I have a dataframe: > df = batch Code. time > a 100. 2019-08-01 00:59:12.000 > a 120. 2019-08-01 00:59:32.000 > a 130. 2019-08-01 00:59:42.000 > a 120. 2019-08-01 00:59:52.000 > b 100. 2019-08-01 00:44:11.000 > b 140. 2019-08-02 00:14:11.000 > b 150. 2019-08-03 00:47:11.000 > c 150. 2019-09-01 00:44:11.000 > d 100. 2019-08-01 00:10:00.000… Read More pandas get time delta between two conditions per group

# pandas get delta from corresponding date in a seperate list of dates

I have a dataframe df a b 7 2019-05-01 00:00:01 6 2019-05-02 00:15:01 1 2019-05-06 00:10:01 3 2019-05-09 01:00:01 8 2019-05-09 04:20:01 9 2019-05-12 01:10:01 4 2019-05-16 03:30:01 And l = [datetime.datetime(2019,05,02), datetime.datetime(2019,05,10), datetime.datetime(2019,05,22) ] I want to add a column with the following: for each row, find the last date from l that is… Read More pandas get delta from corresponding date in a seperate list of dates

# Pandas dataframe how to add a columns based on rank in a dates vector

I have a vector of dates L = [Timestamp(‘2018-07-15 00:00:00’), Timestamp(‘2019-07-15 00:00:00’)] and a dataframe with a date column: df = c1 c2 Date 1. 2. 2018-07-13 16:00:00 1. 7. 2018-07-15 16:00:00 3. 7. 2018-07-15 16:50:00 4. 7. 2018-07-15 19:50:00 2. 2. 2018-07-16 16:00:00 5. 1. 2020-10-10 16:00:00 8. 4. 2018-06-13 16:00:00 5. 4. 2021-12-13… Read More Pandas dataframe how to add a columns based on rank in a dates vector