Questions tagged [running-count]

60 questions
0
votes
0 answers

Running 3Mth total BY multiple columns -Teradata

I am currently working on monthly customer data where the goal is to get a 3mth running total by month and customer (CUST_NUM+CUST_SEQ_NUM). I went the CTE route and was able to produce the expected result when looking at a single customer.…
0
votes
0 answers

Distinct count basis condition for last 3 months

Outlet ID Outlet Name Order Date Product Qty Net Value Mum_1 Prime Traders 12th Oct 2022 RoundBox 3 300 Mum_4 Avon Trading 13th Oct 2022 Slice 100 10 1000 I have date wise transaction data for past 20 months for retail outlets. Any…
0
votes
4 answers

Find the number of rows a value is away from a specific row value in a Python DataFrame

I have the following dataframe, df, and I would like to add the 'distance' column to it, such…
0
votes
3 answers

Setting the last n non NaN vale per group with nan

I have a DataFrame with (several) grouping variables and (several) value variables. My goal is to set the last n non nan values to nan. So let's take a simple example: df = pd.DataFrame({'id':[1,1,1,2,2,], 'value':[1,2,np.nan,…
TiTo
  • 833
  • 2
  • 7
  • 28
0
votes
1 answer

Create Unique IDs using other ID column

I have a dataframe with the following 2 columns, the employee type, name, the column that identify the primary contract and its ID number. Like this one: Name Primary row? Employee Type ID Paulo Cortez Yes Employee 100000 Paulo Cortez …
Paulo Cortez
  • 609
  • 4
  • 10
0
votes
2 answers

The most efficient way to number the instance of a value in a Series

I have a dataframe of visits that includes a person ID column, and a given person may have more than one visit. I want to number the visits for a given person. I can sort the dataframe by visit date, then iterate and count the number of times a…
0
votes
1 answer

Identify non-unique rows, grouping any pairs

I am trying to figure out a non-looping way to identify (auto-incrementing int would be ideal) the non-unique groups of rows (a group can contain 1 or more rows) within each TDateID, GroupID combination. Here is an example DataFrame that looks…
keynesiancross
  • 3,441
  • 15
  • 47
  • 87
0
votes
1 answer

For loop on pandas dataframe causing slow performance

I currently have a loop in a script that is designed to process a raw test data file, and perform a bunch of calculations during the sanitised data. During the script, I need to figure out exactly how many cycles there are in each test. A cycle can…
Murray Ross
  • 163
  • 9
0
votes
1 answer

Cumulative count between two specific events in Pandas

I want to count all steps of each user after 'Start' event in Pandas. My dataset: ID Event 1 Start 1 Event1 1 Start 1 Event1 1 Event2 1 Start 2 Start 2 Event1 2 Start I…
Atakan
  • 45
  • 4
0
votes
1 answer

How to create pandas dataframe column loop on two other columns?

I have a Pandas dataframe and am at a bit of a loss with how to do what I am hoping to. This is a snippet of the dataframe, and I am uploading a screenshot as well. Effectively, I would like to create a new column defined as pitches where count is…
David
  • 45
  • 3
0
votes
1 answer

How to increment duplicate time axis

I have a pd.DataFrame which has duplicate time in its index. Example: from datetime import datetime import pandas as pd time_index = [ datetime(2017, 1, 1, 0, 4, 1, 80000), datetime(2017, 1, 1, 0, 4, 1, 80000), datetime(2017, 1, 1, 0, 4, 1,…
Newskooler
  • 3,973
  • 7
  • 46
  • 84
0
votes
1 answer

Enumerate rows by category

Enumerate values rows by category I have the following dataframe that I'm ordering by category and values: d = {"cat":["a","b","a","c","c"],"val" :[1,2,3,1,4] } df = pd.DataFrame(d) df = df.sort_values(["cat","val"]) Now from that dataframe I…
Luis Ramon Ramirez Rodriguez
  • 9,591
  • 27
  • 102
  • 181
0
votes
1 answer

Adding Counter on Duplicate Keys for Merging

I created a key for merging. Unfortunately, there are some duplicate keys. But I need to keep these rows. I am thinking that for each set of duplicate keys, I can just add counting number 1, 2, 3 and so on to each of the duplicate keys to make them…
ambmil
  • 115
  • 3
  • 9
0
votes
2 answers

COUNTIF Function, reset count if value equals a specific value

I need to list a running count in column A of each occurrence of the value "4A" in column B, but the count needs to reset to 0 if the value in column B equals "2B". I have attached a sample of my workbook, column A shows how I need the count to…
dman
  • 57
  • 1
  • 8
-1
votes
1 answer

Running Total/count with Reset

I currently need to make a query that creates a running total for a user table depending on a specific status and resets once their status changes. I've done the usual running total script but my problem lies on that I'm unsure how to make the count…
1 2 3
4