Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- # Sample dataset
- test_df = pd.DataFrame({'user_id': ['A', 'B', 'C', 'A', 'D', 'E', 'A', 'B']
- , 'app_open_time':['2021-06-20 23:40:32', '2021-06-20 23:50:32', '2021-06-21 23:40:32'
- , '2021-06-20 23:45:32', '2021-06-23 15:20:10', '2021-06-23 15:25:10'
- , '2021-06-20 23:53:10', '2021-06-21 12:45:20' ]})
- # The final dataframe should be created based on the following constraints:
- # Datetime values within 5 minutes(<= 5 minutes) of each other should be counted as 1 for each user id
- # Datetime values should be compared only within an user id instead of across user ids
- # Intended output is given below
- final_df = pd.DataFrame({'user_id': ['A', 'B', 'C', 'D', 'E']
- , 'app_opens': [2, 2, 1, 1, 1]})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement