Counting number of records per month Python

Viewed 71

please help me with creating a dataframe. There is a table containing data: id - user number, FirstVisit - date of the first visit, LastVisit - date of the last visit.

I need to create a table with fields: Month - month, MAU - number of unique users for this month. I have so far created a list of months, through the minimum and maximum date in the table.

df=pd.DataFrame(pd.date_range(visit.FirstVisit.min(),visit.LastVisit.max(), freq='M').strftime('%Y-%m'),columns=['Month'])

I came up with an approximate way how to calculate MAU, this is the Number of unique ID per month, that have FirstVisit<=Month and LastVisit>=Month.

You need to pay attention to the fact that the user, FirstVisit and LastVisit are always the same, but the record can be repeated, because the columns are missing. That is, in fact, duplicates can be deleted and simply the number of records can be counted.

I tried through the function, but so far it does not work, please help.

0 Answers
Related