0

I was trying to create a column with cumulative count per day from a column in google sheet but I was unable to do so.

How to get the cumulative counts?

Public spreadsheet: https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit#gid=1126759670

Question

Find cumulative number per day. Eg for May 7 start from 1,2,3 and for May 8 again start from 1,2,3 and so on.

Required

enter image description here

I need the cumulative count for each day as shown in the figure.

BhishanPoudel
  • 15,974
  • 21
  • 108
  • 169

3 Answers3

2

In J2 I entered

=Arrayformula(IF(LEN(A2:A), ROW(C2:C)-MATCH(C2:C, C2:C,0),))

See if that works for you?

JPV
  • 26,499
  • 4
  • 33
  • 48
2

Also

=ArrayFormula(if(C2:C<>"",countifs(C2:C,C2:C,row(C2:C),"<="&row(C2:C)),))
Tom Sharpe
  • 30,727
  • 5
  • 24
  • 37
0

If you are interested using gspread module, you can get the new column as follows:

import os
import glob
import numpy as np
import pandas as pd

import gspread

path_creds = os.path.expanduser('~/.config/gspread/credentials.json')
gc = gspread.service_account(filename=path_creds) # google service

url = "https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit#gid=1126759670"

parts = url.split('/edit')
url = parts[0]
sh = gc.open_by_url(url)
ws = sh.sheet1
res = ws.get_all_records()
df = pd.DataFrame(res)
df['answer'] = df.groupby('Date')['Company'].transform('cumcount')+1
df

output

enter image description here

BhishanPoudel
  • 15,974
  • 21
  • 108
  • 169