Python Forum
Rolling window and apply code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rolling window and apply code
#1
Hey
I have many large data frames that I need to split into several new data frames.
they need to be split in rolling window split. In this case the window is 12. But it can change.

FOr instance I Now have 250 row that I split into data frames like this... as you can see this is a very long end repetitive way to do this.. I believe there must be a smarter way to do this.

      #df1 = df_all_sales.iloc[0:12].. df2 = df_all_sales.iloc[1:13].. and on and on
        df1 = pd.DataFrame(df_all_sales, columns=['time', 'sales-transaction']).iloc[0:12]
        df2 = pd.DataFrame(df_all_sales, columns=['time', 'sales-transaction']).iloc[1:13]
        df3 = pd.DataFrame(df_all_sales, columns=['time', 'sales-transaction'])iloc[2:14]
        df4 = pd.DataFrame(df_all_sales, columns=['time', 'sales-transaction']).iloc[3:15]
I need help to simplify and reduce the code to something so I can easily access the new Dfs.
Maybe make a for loop or something that can simplify this.
Thanks for advice!
Larz60+ write Jul-15-2022, 09:20 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time, please use bbcode tags on future posts.
Reply


Messages In This Thread
Rolling window and apply code - by JunkBoy - Jul-14-2022, 06:00 PM
RE: Split DF to alot of new DFs - by Larz60+ - Jul-15-2022, 05:22 AM
RE: Split DF to alot of new DFs - by JunkBoy - Jul-15-2022, 06:08 AM
RE: Split DF to alot of new DFs - by perfringo - Jul-15-2022, 10:16 PM
RE: Split DF to alot of new DFs - by JunkBoy - Jul-16-2022, 07:33 AM
RE: Split DF to alot of new DFs - by deanhystad - Jul-16-2022, 01:59 PM
RE: Split DF to alot of new DFs - by JunkBoy - Jul-23-2022, 07:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  apply(pd.Series) until no more array mikisDeWitte 1 2,817 Apr-17-2021, 08:45 PM
Last Post: Caprone
  Hurst Exponent in Rolling Basis illmattic 1 3,893 Jan-06-2021, 09:49 PM
Last Post: illmattic
  Calculating Beta over Rolling Periods illmattic 2 5,480 Sep-27-2020, 11:27 PM
Last Post: Larz60+
  Apply rolling window function over time dimension of 3D data Staph 0 2,214 Jan-01-2020, 08:31 AM
Last Post: Staph
  Grouping data based on rolling conditions kapilan15 0 1,982 Jun-05-2019, 01:07 PM
Last Post: kapilan15
  Pandas .rolling() with some calculations inside irmscher 5 6,267 Apr-04-2019, 11:55 AM
Last Post: scidam
  How to use pandas.rolling mean for 3D input array? Prv_Yadv 1 3,889 Mar-26-2019, 11:49 AM
Last Post: scidam
  Numpy Rolling mean window Thunberd 1 4,865 Jun-14-2018, 01:37 AM
Last Post: Larz60+
  Creating a matrix of rolling variances vvvcvvcv 1 2,789 May-26-2018, 12:51 PM
Last Post: killerrex
  Rolling sum for a window of 2 days (Pandas) klllmmm 1 10,371 Feb-02-2018, 03:24 PM
Last Post: klllmmm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020