Questions tagged [cumsum]

Cumsum is a MatLab, NumPy, Pandas and R function that returns the cumulative sum along different dimensions of an array.

Cumsum is a MatLab, NumPy, Pandas and R function that returns the cumulative sum along different dimensions of an array.

799 questions
0
votes
1 answer

How can I make this plot in R? xlim and Date issue

First of all, I would like to thank you for your attention. Here it's my problem: I have a dataframe, this is it's structure (I have deleted some rows): DATE PRODUCT ORIGIN 11/03/2013 FV Turkey 11/03/2013 BMPT …
Eka
  • 47
  • 1
  • 7
0
votes
1 answer

R cumsum for selected months across multiple years

I would like to compute a Cumulative Sum according to Center Disease Control definition. I have weekly data from 25 District since 2008 to now. Site1 Site2 Site3 Site4 Site5 Site6 Site7 Site8 Site9 2011-45 1 1 1 1 2 …
user3355655
  • 463
  • 3
  • 15
0
votes
2 answers

Gettting cumulative sum of previous values except for the first value

I am running a code in R, the sample of which is as below with a small dataset - library(plyr) Ex<-structure(list(X1 = c(-36.8598, -37.1726, -36.4343, -36.8644, -37.0599, -34.8818, -31.9907, -37.8304, …
RHelp
  • 815
  • 2
  • 8
  • 23
0
votes
2 answers

Numpy cumulative sum for csv rows gives type error

I'm using cumsum function to calculate cumulative sum of a csv column(rows). Input looks like this: input (average_): 1 0.000053 0.004531 0.010447 0.051962 2 0.000589 0.004518 0.009801 0.052226 3 0.000083 0.004581 …
PyLearner
  • 239
  • 2
  • 5
  • 11
0
votes
1 answer

Generalizing/looping conditional cumulative sum algorithm across multiple columns in R

I have found a lot of questions and answers regarding conditional cumulative sums in R, but so far, all the ones I have seen involve conditionally summing a single variable. What I am trying to do is generalize the conditional sum formula so that…
0
votes
2 answers

Custom cumulative sum with decay factor

I am trying to optimize the following code. dim <- c(10000,100) m <- matrix(sample(0:10, prod(dim), replace = TRUE), nrow = dim[1], ncol = dim[2]) system.time({ output <- matrix(0, nrow = dim[1], ncol = dim[2]) for (i in 1:dim[1]){ …
nassimhddd
  • 8,340
  • 1
  • 29
  • 44
0
votes
2 answers

Using Numpy to Count Numbers in a range

I've been trying to write some code which will add the numbers which fall into a certain range and add a corresponding number to a list. I also need to pull the range from a cumsum range. numbers = [] i=0 z = np.random.rand(1000) arraypmf =…
-1
votes
1 answer

loop through python data frame and sum column value

What I am attempting is to loop through a df in python and add B2 to B3 then check to see if the sum is equal to or greater than 950 if so return the value of A3 if not take the product of B2 and B3 and now also add in B4. if that meets the prior…
brewig615
  • 1
  • 2
-1
votes
1 answer

How to calculate cumulative covered distances over a sequence of different days and nights in Python

I would calculate the cumulative covered distance performed by a fish during each day and night of the entire study period. I have this kind of dataframe, where 'Dates' corresponds to the date of the recording, 'Covered Distance' corresponds to the…
toms
  • 103
  • 4
-1
votes
1 answer

Value error: The truth value of array is ambigous

I am trying to translate the following code from matlab: a=rand; i=1; while a > cumsum(T_a(Index_a(end,1),1:i)) i=i+1; end Where T_a is a 15x15 array and Index_a is a 51x1 double. My python attempt is: a=np.random.uniform(0,1) …
-1
votes
1 answer

Converting Python code to pyspark environment

How can I have the same functions as shift() and cumsum() from pandas in pyspark? import pandas as pd temp = pd.DataFrame(data=[['a',0],['a',0],['a',0],['b',0],['b',1],['b',1],['c',1],['c',0],['c',0]], columns=['ID','X']) temp['transformed'] =…
-1
votes
1 answer

Assign value to a column with while and cumsum conditions

I have tried the solution but it didn't work for me. I'm going to explain the complete problem. What I have to do is an optimization to assign clients to commercial employees. The columns will be "center" (commercial department), "client" (nº of…
joss
  • 13
  • 2
-1
votes
1 answer

cumulative sum but keeping a column user for aggregation

I have a df like this one: player_profile category upgrade_n level 0 Weak common_caddie 1 13.0 1 Weak common_caddie 1 25.0 2 Weak common_caddie 1 36.0 3 Weak …
ianux22
  • 405
  • 4
  • 16
-1
votes
1 answer

Cummulative sum in R with unusual conditions

I'm trying to solve a much bigger problem, but this might be the key to the castle. The example I'm giving has an order to it because there are dates but I dropped them for simplicity. I would like to have a changing sum. The sum is equal to…
ClaireR
  • 21
  • 7
-1
votes
2 answers

Rolling sum of groups by period

I have got this dataframe: lst=[['01012021','A',10],['01012021','B',20],['02012021','A',12],['02012021','B',23]] df2=pd.DataFrame(lst,columns=['Date','FN','AuM']) I would like to get the rolling sum by date and FN. The desired result looks like…
Bsleon
  • 135
  • 6