I have a dataframe with each row representing a visit by a user, including a userid column and a date column. I'd like to calculate the number of unique visitors to date (not just unique visitors for that date - unique visitors from the first date of dataframe until the row date) for each date in the dataframe
Dataframe:
date clientid
2015-01-01 12345
2015-01-01 12346
2015-01-02 12345
2015-01-02 12347
2015-01-03 12347
Expected output:
date unique_visitors_to_date
2015-01-01 2
2015-01-02 3
2015-01-03 3
This code would work in theory but the for loop is stuck in purgatory and also I think for loops are not the "right" way to do it.
for i in range(0,519585):
visit['cumulative'].loc[i] = visit[visit.date <=
visit.date.loc[i]].clientid.nunique()