Skip to content
Advertisement

How to create a specific date_range for each unique id in a dataframe?

I want to create a date range for each customer in a dataset. Each customer has its own range. How can this be done without a for loop?

Sample data:

JavaScript

Now I want to have one month for each row for each customer, for their min and max dates respectively, to get:

Expected output:

JavaScript

My attempt is to use a for loop, iterating through each customer, but it is too slow. How to make it faster?

JavaScript

Advertisement

Answer

JavaScript
JavaScript

Further if you want to convert the date column then

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement