Advertisement
Guest User

test

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