cumsum Questions

3

Solved

I have a dataframe like below: A B C 1 1 1 2 0 1 3 0 0 4 1 0 5 0 1 6 0 0 7 1 0 I want the number of occurence of zeroes from df['B'] under the following condition: if(df['B']<df['C']): #cou...
Tubular asked 13/9, 2019 at 14:11

2

Solved

I have a pandas dataframe with two columns like this, Item Value 0 A 7 1 A 2 2 A -6 3 A -70 4 A 8 5 A 0 I want to cumulative sum over the column, Value. But while creating the cumulative sum if ...
Peptone asked 15/8, 2019 at 13:44

7

Solved

I have a vector of TRUEs and FALSEs: x <- c(F,F,F,T,T,T,F,F,F,T,T,T,F,T,T) I'd like to elegantly (and in base) identify the position of the last TRUE before it changes to FALSE. The followin...
Simoniac asked 29/6, 2019 at 2:41

2

I have a numeric series like [0,0,0,0,1,1,1,0,0,1,1,0]. I would like to calculate the numeric sum from the last non-zero values. i.e the cumsum will be reset to zero once a zero entry occurs. inpu...
Discuss asked 12/6, 2019 at 22:10

7

I have a (long) list in which zeros and ones appear at random: list_a = [1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1] I want to get the list_b sum of the list up to where 0 appears where 0 appears, ret...
Heiney asked 15/2, 2018 at 10:31

1

Solved

Why are these two operations different? library(lubridate) library(magrittr) > seconds_to_period(1:1000) %>% cumsum %>% sum [1] 14492440 > 1:1000 %>% cumsum %>% sum [1] 16716700...
Glossolalia asked 23/3, 2019 at 15:16

3

I have a time series data frame and want to compute cumulative returns for stock symbols intra-day for a range of dates. When the symbol and/or date changes the cumulative return should reset. Any ...
Outstand asked 24/5, 2013 at 18:45

1

Solved

My question is very similar to Cumsum within group and reset on condition in pandas and Pandas: cumsum per category based on additional condition but they don't quite get me there due to my conditi...
Arnelle asked 31/10, 2018 at 8:39

6

Solved

I have a numpy boolean array w=np.array([True,False,True,True,False,False,False]) I would like to get the index of the first time there are at n_at_least false values. For instance here `n_at...
Wastebasket asked 6/4, 2018 at 13:20

4

Solved

I have a series that contains NaN and True as a value. I want another series to generate a sequence of number, such that whenever NaN comes put that series value as 0 and In between of Two NaN rows...
Wormseed asked 7/2, 2018 at 8:19

1

I have a dataframe with two columns ID and Activity. The activity is either 0 or 1. I want a new column containing a increasing number since the last activity was 1. However, the count should only ...
Gaygaya asked 10/12, 2017 at 17:42

2

I would like to perform the following task. Given a 2 columns (good and bad) I would like to replace any rows for the two columns with a running total. Here is an example of the current dataframe a...
Jackson asked 9/11, 2017 at 9:43

2

Solved

I have a data.table dt as follows. df <- data.frame(t1 = rep(0,5), t3 = c(12, 5, 8,9, 5), t7= c(25, 48, 7, 9, 14)) dt <- setDT(df) dt t1 t3 t7 1: 0 12 25 2: 0 5 48 3: 0 8 7 4: 0 9 9 5: 0 5 ...
Chromolithography asked 27/10, 2017 at 15:42

4

I have an array of values a = (2,3,0,0,4,3) y=0 for x in a: y = (y+x)*.95 Is there any way to use cumsum in numpy and apply the .95 decay to each row before adding the next value?
Cass asked 7/3, 2015 at 12:55

2

I have a data frame like: customer spend hurdle A 20 50 A 31 50 A 20 50 B 50 100 B 51 100 B 30 100 I want to calculate additional column for Cumulative which will reset base on the same c...
Tobytobye asked 17/10, 2017 at 7:1

1

Solved

Suppose I have a scipy.sparse.csr_matrix representing the values below [[0 0 1 2 0 3 0 4] [1 0 0 2 0 3 4 0]] I want to calculate the cumulative sum of non-zero values in-place, which would chan...
Luthern asked 3/8, 2017 at 19:7

3

Solved

Suppose I have the following dataframe: C1 C2 C3 C4 0 1 2 3 0 1 4 0 0 0 2 0 0 0 3 3 0 3 0 0 Then I want to add another column such that it will display the number of zero valued column th...
Smear asked 23/7, 2017 at 4:25

1

Solved

Using pandas, what is the easiest way to calculate a rolling cumsum over the previous n elements, for instance to calculate trailing three days sales: df = pandas.Series(numpy.random.randint(0,10,...
Hypanthium asked 27/5, 2017 at 21:21

3

Solved

I have this dataframe Poloniex_DOGE_BTC Poloniex_XMR_BTC Daily_rets perc_ret 172 0.006085 -0.000839 0.003309 0 173 0.006229 0.002111 0.005135 0 174 0.000000 -0.001651 0.004203 0 175 0.000000 0.007...
Crackerjack asked 12/2, 2016 at 14:52

2

Solved

[1, 1, 1, 0, 0, 0, 1, 1, 0, 0] I have a NumPy array consisting of 0's and 1's like above. How can I add all consecutive 1's like below? Any time I encounter a 0, I reset. [1, 2, 3, 0, 0, 0, 1, 2...
Coccyx asked 9/2, 2017 at 5:37

1

Solved

I have a pandas dataframe defined as: A B SUM_C 1 1 10 1 2 20 I would like to do a cumulative sum of SUM_C and add it as a new column to the same dataframe. In other words, my end goal is to ha...
Courses asked 25/1, 2017 at 18:48

2

Solved

I have spent a few hours now trying to do a "cumulative group by sum" on a pandas dataframe. I have looked at all the stackoverflow answers and surprisingly none of them can solve my (very elementa...
Henig asked 23/1, 2017 at 14:42

1

Solved

given the simplified data set.seed(13) user_id = rep(1:2, each = 10) order_id = sample(1:20, replace = FALSE) cost = round(runif(20, 1.5, 75),1) category = sample( c("apples", "pears", "chicken")...
Gasser asked 7/12, 2016 at 14:57

2

Solved

I am trying to create a column in a very large data frame (~ 2.2 million rows) that calculates the cumulative sum of 1's for each factor level, and resets when a new factor level is reached. Below ...
Zyrian asked 9/3, 2016 at 17:27

1

I have created the following reproducible example: library(data.table) Col_1 <- 0.05 Col_2 <- c( "B", "A", "C", "B", "C", "A", "C", "B", "B", "A" ) Col_3 <- 1000 Col_4 <- "" data <-...
Anaphylaxis asked 17/11, 2015 at 15:7

© 2022 - 2024 — McMap. All rights reserved.