0

I have a dataframe which has measures every minute from different sensors. I would like to select the measures made in one day, being this day chosen randomly.

This is the dataframe first 10 rows:

                   Time   CO2     H         T
0  21-Dec-2018 15:04:00  1540  59.3  17.95000
1  21-Dec-2018 15:05:00  1440  55.6  18.15000
2  21-Dec-2018 15:06:00  1426  53.7  18.25000
3  21-Dec-2018 15:07:00  1426  52.3  18.35000
4  21-Dec-2018 15:08:00  1382  51.3  18.45000
5  21-Dec-2018 15:09:00  1338  50.3  18.62019
6  21-Dec-2018 15:10:00  1304  49.4  18.75000
7  21-Dec-2018 15:11:00  1274  48.6  18.92019
8  21-Dec-2018 15:12:00  1262  47.8  19.52019
9  21-Dec-2018 15:13:00  1258  47.2  19.22019

For example, if the range of dates goes from '21-Dec-2018 15:04:00' to '31-Dec-2018 23:59:00', randomly select a day, suppose the day 24. After the day is randomly selected get all the measures from that day (They should be 1440 in total, one per minute).

Is this possible?

1 Answer 1

1

Start by casting the date column to datetime with pod.to_datetime, and the use DataFrame.sample to take a random sample from the days it contains. Then use it to index the dataframe:

df['Time'] = pd.to_datetime(df.Time)
random_day = df.Time.dt.day.sample(1).values.item()
df_on_random_day = df[df.Time.dt.day.eq(random_day)]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.