0

I am looking for a elegant solution to create multiple dataframe with mixed up timestamps

I have a dataframe with more than thousand of rows with 16 columns, and one of columns have timestamp value like :

2021-09-28 00:00:00 ~ 2021-09-28 23:59:59

Also, the timestamp value is not continuse on the dataframe, and mixed up the timestamp.

Example

IN [1] : df["datetime"][24082:24085]
OUT [1] :
24082   2021-09-28 07:25:21.446
24083   2021-09-28 07:25:22.444
24084   2021-10-01 19:49:40.549
24085   2021-10-01 19:49:41.549

What I am trying to do is creating multiple dataframes from the dataframe depends on the date of timestamp, such as;

df1 is the rows with 2021-09-28 00:00:00.001 ~ 23:59:59.999
df2 is the rows with 2021-09-29 00:00:00.001 ~ 23:59:59.999
df3 is the rows with 2021-09-30 00:00:00.001 ~ 23:59:59.999
     ...
dfn is the rows with latest date

How can I achieve the above dataframes?

1 Answer 1

2

Use groupby with Grouper:

for date, data in df.groupby(pd.Grouper(key='datetime', freq='D')):
    # do_something_with_your_data
    print(data)
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.