Created
August 27, 2021 15:49
-
-
Save marcosan93/9b32ee02e9cce35c7e0d92e586eaef7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def randomtimes(start, end, n): | |
| """ | |
| Generates random time stamps based on a given amount between two time periods. | |
| """ | |
| # The timestamp format | |
| frmt = "%Y-%m-%d %H:%M:%S" | |
| # Formatting the two time periods | |
| stime = datetime.datetime.strptime(start, frmt) | |
| etime = datetime.datetime.strptime(end, frmt) | |
| # Creating the pool for random times | |
| td = etime - stime | |
| # Generating a list with the random times | |
| times = [(random.random() * td + stime).strftime(frmt) for _ in range(n)] | |
| return times | |
| # Setting the start and end times | |
| start = "2021-08-01 00:00:00" | |
| end = "2021-08-24 00:00:00" | |
| df['last_login'] = randomtimes(start, end, num_users) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment