0
votes

I have some dates like this:

2015-02-02 14:19:00

I have 20000 records and 14 different days, i would like to split the dataset into 14 different part to have 14 different time series, one every day.

enter image description here

I'd like to create for each day a variable that contains only the records in the day considered.

1
Can you add more details to your question, is not clear what do you want to achieve. Thanks - EnriqueBet
I want to split the dataset into different days to compare them - abpan8
Can you explain more? Give an example of "14 different parts", please. I mean, I can split one date only on 6 parts. - Demian Wolf
you should probably add some examples from your records, any code that you have attempted as well and errors you are finding. Please refer to these guidelines [how to ask?] (stackoverflow.com/help/how-to-ask) - EnriqueBet

1 Answers

1
votes

IIUC

# sample data
df = pd.DataFrame(pd.date_range('2020-01-01', '2020-01-14', freq='5T'), columns=['date'])
# list comprehension to spit groups into separate frames
dfs = [g for _,g in df.groupby(df['date'].dt.date)]

or you can use dict comprehension if you want the key to be the date

dfs = {idx:df for idx,df in df.groupby(df['date'].dt.date)}
# below is how you call each frame by the date
dfs[datetime.date(2020, 1, 1)]

new example with multiple cols

df = pd.DataFrame(np.transpose([pd.date_range('2020-01-01', '2020-01-14', freq='5T'),
                                np.random.randint(1,10,3745)]), columns=['date', 'col'])
dfs = [g for _,g in df.groupby(df['date'].dt.date)]
print(dfs[0])

                   date col
0   2020-01-01 00:00:00   3
1   2020-01-01 00:05:00   3
2   2020-01-01 00:10:00   6
3   2020-01-01 00:15:00   6
4   2020-01-01 00:20:00   3