1

I have a large data frame with around 264k rows that I want to split by 7 day's range, the data frame looks like below-

CreatedDate CreatedTime    Symbol   Type
0   7/1/2021    9:30:00 AM  AAPL    SWEEP
1   7/1/2021    9:30:00 AM  TSLA    BLOCK
2   7/1/2021    9:30:00 AM  AAPL    SWEEP
3   7/1/2021    9:30:00 AM  AMD     BLOCK
4   7/1/2021    9:30:01 AM  GOEV    BLOCK
........................................
........................................
264754  9/24/2021   3:59:51 PM  PLTR    SWEEP
264755  9/24/2021   3:59:55 PM  TSLA    SWEEP
264756  9/24/2021   3:59:57 PM  TSLA    BLOCK
264757  9/24/2021   3:59:58 PM  RUN     SWEEP
264758  9/24/2021   3:59:58 PM  AAPL    BLOCK

What I tried? Currently it's splitting the rows for each day

# Export to 7days_split.csv files.
for date, data in options_flow.groupby('CreatedDate'):
    data.to_csv("{}.csv".format(date))

What I want?

I want to split the CSV on the CreatedDate column by 7 days range e.g 1st CSV will contain rows of the first 7 days, 2nd CSV will continue rows next 7 day's and so on.

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
  • 1
    Does this answer your question? [Grouping by date range with pandas](https://stackoverflow.com/questions/46839032/grouping-by-date-range-with-pandas) – ddejohn Sep 26 '21 at 15:34

0 Answers0