Python Forum
How to accumulate volume of time series
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to accumulate volume of time series
#1
Hello, I am working with a time series containing rain. the data looks like

intensity
0.1
0.2
0.1
0.1
0.0
0.0
0.2

And I want to be able to calculate the accumulated rain like this:
0.1
0.2+0.1
0.1+0.3
0.1+0.4
0.0+0.5
0.0+0.5
0.2+0.5

                    
for i in range(len(Needed_vol) - 1):
                        Needed_vol.loc[i + 1] = Needed_vol.loc[i] + Needed_vol.loc[i + 1]
So far I am doing it like this, and it works fine, it does, however, take too much time, as I am working with a file containing more than 10000 timestamps, so I would like to know if there is a way to do this more efficiently. It is important that it sums it up like the example
Hope someone can help ☺
Reply
#2
pandas has built-in cumsum()
amdi40 likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(Feb-14-2022, 11:25 AM)perfringo Wrote: pandas has built-in cumsum()


Thanks, that was exactly what I was looking for! :D
Reply
#4
I might have been too quick to ask my question xd

I still want to do this
intensity
0.1
0.2
0.1
0.1
0.0
0.0
0.2

And I want to be able to calculate the accumulated rain like this:
0.1
0.2+0.1
0.1+0.3
0.1+0.4
0.0+0.5
0.0+0.5
0.0+0.5
0.0+0.5
0.0+0.5
0.0+0.5
0.2+0.5

And cumsum does this, but I also want to subtract the data with a constant removing rate.
(0.1+()) - 0.1 new dt: 0
(0.2+0)-0.1 0.1
(0.1+0.1)-0.1 0.1
(0.1+0.1)-0.1 0.1
(0.0+0.1)-0.1 0
(0.0+0.0)-0.1 0(dont want it to be negative)
(0.0+0.0)-0.1 0
(0.0+0.0)-0.1 0
(0.0+0.0)-0.1 0
(0.0+0.5)-0.1 0.4
(0.2+0.4)-0.1 0.5

I thought about doing it like this:
Vol = vol_added - vol_removed
Vol_accc=vol.cumsum
And that would work if there was a way to reset vol_acc every time I in acc was < 0, but I can't figure out quite how to do to it
I have also tried this, but the problem is that the file I am working with is so large that I need a method as efficient as the cumsum method :/
for i in range(len(volume) - 1):
    if i >= 0:
       volume.loc[i] = (volume.loc[i] + volume.loc[i + 1])-vol_out
    else:
        i=0
Hope you can help me again :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help: Conversion of Electricity Data into Time Series Data SmallGuy 3 1,206 Oct-04-2023, 03:31 PM
Last Post: deanhystad
  Time Series Production Process Problem Mzarour 1 2,130 Feb-28-2023, 12:25 PM
Last Post: get2sid
  reduce time series based on sum condition amdi40 0 1,099 Apr-06-2022, 09:09 AM
Last Post: amdi40
  Recommendations for ML libraries for time-series forecast AndreasPython 0 1,884 Jan-06-2021, 01:03 PM
Last Post: AndreasPython
  Time Series forecating with multiple independent variables Krychol88 1 1,862 Oct-23-2020, 08:11 AM
Last Post: DPaul
  how to handling time series data file with Python? aupres 4 2,976 Aug-10-2020, 12:40 PM
Last Post: MattKahn13
  Changing Time Series from Start to End of Month illmattic 0 1,857 Jul-16-2020, 10:49 AM
Last Post: illmattic
  HELP- DATA FRAME INTO TIME SERIES- BASIC bntayfur 0 1,747 Jul-11-2020, 09:04 PM
Last Post: bntayfur
  Differencing Time series and Inverse after Training donnertrud 0 4,096 May-27-2020, 06:11 AM
Last Post: donnertrud
  How can I convert time-series data in rows into column srvmig 0 2,060 Apr-11-2020, 05:40 AM
Last Post: srvmig

Forum Jump:

User Panel Messages

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