Python Forum
Multiprocessing on python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiprocessing on python
#11
Well now I've discovered rolling on polars dataframes - could I use this to eliminate my while loop altogether?

df = pl.read_csv(sys.argv[1])
print(df)
df = df.with_columns(pl.col("ts_event").cast(pl.Datetime))
print(df)

# Define your rolling window in time
window_duration = "35s"  # 35 seconds window
every_duration = "1s"    # Shift the window every 1 second

out = df.rolling(index_column = 'ts_event', period = '30s', offset = '1s').agg(pl.col('size').sum())

print(out)
So as practice, ts_event in my CSV file is nanosecond unix timestamps. I first convert this column to datetime objects. The column 'size' is just a column of integers, say typically ranging anywhere from between 1-500 in value.

I want to take the first 30s worth of rows, and find the sum of the size col in that 35s. Then I want to increment up by one second and find the next sum.

For example, let's say my data starts at 08:00:00 -

So first I want to find the sum of the size col beween

8:00:00-8:00:30
then
8:00:01-8:00:31
8:00:02-8:00:32

and so on...

And for now we can just deposit these results into another dataframe.

So with the above code I posted I get the error

Error:
- If your data is ALREADY sorted, set the sorted flag with: '.set_sorted()'.
My ts_event col is already sorted chronologically. But I can't figure out the syntax for how to set that flag in my code - no matter where I try it, it keeps throwing me another error.

How do I set the '.set_sorted()' flag?
Reply


Messages In This Thread
Multiprocessing on python - by sawtooth500 - Apr-01-2024, 01:31 AM
RE: Multiprocessing on python - by deanhystad - Apr-01-2024, 01:57 AM
RE: Multiprocessing on python - by sawtooth500 - Apr-01-2024, 02:24 AM
RE: Multiprocessing on python - by sawtooth500 - Apr-01-2024, 04:41 AM
RE: Multiprocessing on python - by deanhystad - Apr-01-2024, 09:51 AM
RE: Multiprocessing on python - by sawtooth500 - Apr-01-2024, 05:12 PM
RE: Multiprocessing on python - by deanhystad - Apr-01-2024, 05:51 PM
RE: Multiprocessing on python - by jefsummers - Apr-01-2024, 07:19 PM
RE: Multiprocessing on python - by sawtooth500 - Apr-02-2024, 01:53 AM
RE: Multiprocessing on python - by sawtooth500 - Apr-02-2024, 03:07 AM
RE: Multiprocessing on python - by sawtooth500 - Apr-02-2024, 03:05 PM
RE: Multiprocessing on python - by deanhystad - Apr-02-2024, 04:14 PM
RE: Multiprocessing on python - by sawtooth500 - Apr-02-2024, 06:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to run existing python script parallel using multiprocessing lravikumarvsp 3 5,001 May-24-2018, 05:23 AM
Last Post: lravikumarvsp

Forum Jump:

User Panel Messages

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