Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime
- dates = {}
- with open('v.csv') as f: # Path to csv file
- for line in f.readlines():
- values = line.strip().split(',') # List of comma-separated values, strip() used to get rid of '\n' symbol in the end
- user_id = values[3] # Index of id
- date = datetime.strptime(values[6], '"%Y-%m-%d %H:%M:%S"') # Parsing sate and time from a string to datetime object
- if user_id in dates: # If we already have a date for this user
- dates[user_id] = min(date, dates[user_id]) # Minimum of date we just read and the one we recorded before
- else:
- dates[user_id] = date # Date we just read
- for item in dates.items():
- print("User with id {} made first purchase on {}".format(item[0], item[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement