Questions tagged [running-count]
60 questions
1
vote
1 answer
Running count of rows before a specific date for each group in a dataframe
I have the following Pandas dataframe in Python:
ID Date
E105 28/4/2021
E105 28/2/2021
E105 23/12/2020
E105 29/11/2020
E076 7/7/2021
E076 20/6/2021
E076 26/5/2021
E076 8/4/2021
E076 3/3/2021
E076 3/2/2021
E076 …

Nayr borcherds
- 395
- 1
- 6
1
vote
3 answers
Add column with a specific sequence of numbers depending on value
I have this dataframe:
df = pd.DataFrame({
'ID': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
'Condition': [False, False, True, False, False, False, False, False, False, False, True, False]})
ID Condition
0 1 False
1 …

nokvk
- 333
- 2
- 7
1
vote
1 answer
Cumulatively count values between range by group in a pandas dataframe
Say I have the following data. For each user_id I want to get a cumulative count every time the difference score is <= -2 until it reaches a positive value. The count should then reset to zero and stay at that value until the next <= -2 is…

Micah
- 25
- 3
1
vote
2 answers
Number timestamps based on time of timestamp
I have up to three different timestamps for each day in dataframe. In a new column called 'Category' I want to give them a number from 1 to 3 based on time of the timestamp. Almost like a partition by with rank in sql.
Something like: for each day…

ssiftekhar
- 31
- 3
1
vote
2 answers
More elegant way to cumcount based on a condition in python pandas
I have the following df consisting of two teams and their point differentials for games they have played.
df = pd.DataFrame({
'Team':['A','A','A','A','A','B','B','B','B','B'],
'Point_Diff':[-4,5,-1,2,2,6,-5,-4,3,-1]}
)
df
Team …

bismo
- 1,257
- 1
- 16
- 36
1
vote
2 answers
Copying and appending rows to a dataframe with increment to timestamp column by a minute
Here is the dataframe I have:
df = pd.DataFrame([[pd.Timestamp(2017, 1, 1, 12, 32, 0), 2, 3],
[pd.Timestamp(2017, 1, 2, 12, 32, 0), 4, 9]],
columns=['time', 'feature1', 'feature2'])
For every timestamp value found in…

Sushanth
- 2,224
- 13
- 29
1
vote
3 answers
Pandas Cumcount() over multiple columns
I have a dataframe that looks like this:
data = {'exercise': ['squat', 'squat', 'squat', 'squat', 'bench', 'bench', 'bench', 'bench', 'squat', 'squat', 'squat', 'squat', 'bench', 'bench', 'bench', 'bench'],
'session': [0, 0, 0, 0, 0, 0, 0,…

Mattias Thalén
- 123
- 6
1
vote
1 answer
Pandas Custom Cumcount
I am trying to cumulative count the column Value grouped by the column User, but only increasing the count if there have been a different value in between.
The best I was able to achieve was a normal cumcount using:
df['Cumcount'] =…

samueuh
- 19
- 2
1
vote
1 answer
Manipulation of a dataframe index on the basis of values from another column
Suppose I have a dataframe which currently has data like this:
T week
0 T-1
1 T-1
2 T-1
3 T-1
4 T-2
5 T-2
6 T-2
7 T-3
8 T-3
9 T-3
10 T-3
I want to group the index in such a way that it corresponds with the T- group I am dealing with,…

dexter27
- 55
- 1
- 5
1
vote
2 answers
Sort by column and append counter using pandas
I have a large data frame (>1m rows, 10+ cols) that I need to do the following to:
Group by two of the columns (A & B in example)
Sort within the grouping by another column (C in example)
Append an incremental counter to another column,…

BrT
- 619
- 1
- 5
- 15
0
votes
1 answer
Generate summary with counts of joiners, leavers and running count of users
I have a table with a large number of events that have happened, like the following:
ts
event
2023-05-09 19:20:19 UTC
joined
2023-01-16 09:34:02 UTC
joined
2022-08-19 10:02:44 UTC
left
2022-10-06 10:11:12 UTC
joined
2021-10-06…

digibake
- 448
- 4
- 12
0
votes
1 answer
mysql: get running count over time based on start and end timestamps
I have a workflows table with columns (processID, started_at, ended_at)
How can I build running counts of actively running process IDs per a given timestamp as a timeseries from data tabulated below:
Table of process timestamps:
id started_at …

rajivRaja
- 527
- 3
- 6
- 16
0
votes
1 answer
Crystal Reports - Running total excluding singular row
I'm not sure the best way to phrase this, so I will try: Is there a way to count a total of distinct IDs, but exclude the IDs that only have code 1111? But include the rows that have 1111 PLUS any other…

Kylie
- 1
0
votes
0 answers
Excel - Formula to add one number to another, but remain unchanged if one number is deleted
in excel I want to record a monthly total of items distributed and an all-time total. At the start of a new month, the monthly totals reset back to 0, but I want the all-time total to remain unchanged. This all-time number should only increase over…

Stu
- 1
0
votes
1 answer
How do i analyze the running time of a function with a for loop with an if statement?
For example, let the function consist:
def myfunc():
total = 0
for i in range(0, n):
total+=i
if total >= n:
return total
return 0
What would the running time be?
I cant seem to figure out a way to analyze this…