$ cat test1.py
#!/usr/bin/env python3
import random
import sys
import os
import pandas as pd
from datetime import datetime, date, timedelta
from dateutil.relativedelta import relativedelta
def get_tag_at_random():
tags = ['John', 'Paul', 'George', 'Ringo']
return random.choice(tags)
def create_dummy_df(N):
colnames = ["date", "tag", "count"]
df = pd.DataFrame([], columns=colnames)
end_date = datetime.today()
x = [random.randint(0, 100000) for p in range(0, N)]
d_list = []
for i in x:
# print(i)
target_date = end_date + relativedelta(seconds=i)
date_str = datetime.strftime(target_date, '%Y-%m-%d %H:%M:%S')
tag = get_tag_at_random()
value = random.randint(0, 30)
print(date_str, tag, value)
temp = pd.Series(
[
date_str, tag, value
],
index=df.columns,
)
df = df.append(temp, ignore_index=True)
end_date = target_date
return df
if __name__ == "__main__":
df = create_dummy_df(N=50)
print(df)
csv_file = sys.argv[0].replace(".py", ".csv")
df.to_csv(csv_file, index=False)
print(csv_file, "created.")
2021-10-25 09:25:00 George 14
2021-10-25 22:47:36 Paul 16
2021-10-26 07:45:27 George 20
2021-10-26 20:43:36 Paul 25
2021-10-27 02:09:55 Paul 27
2021-10-27 17:31:10 John 7
2021-10-28 21:04:15 Ringo 10
2021-10-28 22:28:52 Ringo 26
2021-10-29 13:55:21 Paul 15
2021-10-29 21:26:50 John 18
2021-10-30 02:26:20 Paul 19
2021-10-30 15:43:50 George 15
2021-10-31 11:44:00 Paul 5
2021-11-01 13:05:17 George 2
2021-11-02 08:08:23 George 16
2021-11-02 15:58:28 John 19
2021-11-03 10:15:57 Paul 15
2021-11-03 23:51:14 John 21
2021-11-04 04:53:00 Ringo 2
2021-11-04 15:07:47 Paul 8
2021-11-04 19:27:10 George 6
2021-11-05 15:49:13 John 8
2021-11-06 06:18:58 George 18
2021-11-06 14:45:47 Paul 6
2021-11-07 10:06:35 George 8
2021-11-08 01:22:00 George 16
2021-11-08 18:59:33 Ringo 27
2021-11-08 22:40:46 John 8
2021-11-09 08:27:50 Ringo 9
2021-11-10 02:40:04 John 17
2021-11-11 06:04:45 John 4
2021-11-11 19:22:35 George 19
2021-11-12 16:36:37 George 17
2021-11-13 01:01:19 George 29
2021-11-13 07:18:08 George 14
2021-11-14 02:23:27 Paul 15
2021-11-15 04:49:58 Paul 18
2021-11-15 23:45:46 Ringo 16
2021-11-16 12:22:14 Paul 0
2021-11-17 03:37:26 George 8
2021-11-17 08:31:07 George 7
2021-11-18 02:14:45 George 9
2021-11-18 12:25:14 Paul 25
2021-11-19 03:54:08 John 14
2021-11-19 23:07:52 Paul 4
2021-11-20 10:29:48 George 12
2021-11-20 15:54:49 John 22
2021-11-21 07:08:04 John 23
2021-11-22 00:51:01 John 28
2021-11-22 05:03:36 John 8
date tag count
0 2021-10-25 09:25:00 George 14
1 2021-10-25 22:47:36 Paul 16
2 2021-10-26 07:45:27 George 20
3 2021-10-26 20:43:36 Paul 25
4 2021-10-27 02:09:55 Paul 27
5 2021-10-27 17:31:10 John 7
6 2021-10-28 21:04:15 Ringo 10
7 2021-10-28 22:28:52 Ringo 26
8 2021-10-29 13:55:21 Paul 15
9 2021-10-29 21:26:50 John 18
10 2021-10-30 02:26:20 Paul 19
11 2021-10-30 15:43:50 George 15
12 2021-10-31 11:44:00 Paul 5
13 2021-11-01 13:05:17 George 2
14 2021-11-02 08:08:23 George 16
15 2021-11-02 15:58:28 John 19
16 2021-11-03 10:15:57 Paul 15
17 2021-11-03 23:51:14 John 21
18 2021-11-04 04:53:00 Ringo 2
19 2021-11-04 15:07:47 Paul 8
20 2021-11-04 19:27:10 George 6
21 2021-11-05 15:49:13 John 8
22 2021-11-06 06:18:58 George 18
23 2021-11-06 14:45:47 Paul 6
24 2021-11-07 10:06:35 George 8
25 2021-11-08 01:22:00 George 16
26 2021-11-08 18:59:33 Ringo 27
27 2021-11-08 22:40:46 John 8
28 2021-11-09 08:27:50 Ringo 9
29 2021-11-10 02:40:04 John 17
30 2021-11-11 06:04:45 John 4
31 2021-11-11 19:22:35 George 19
32 2021-11-12 16:36:37 George 17
33 2021-11-13 01:01:19 George 29
34 2021-11-13 07:18:08 George 14
35 2021-11-14 02:23:27 Paul 15
36 2021-11-15 04:49:58 Paul 18
37 2021-11-15 23:45:46 Ringo 16
38 2021-11-16 12:22:14 Paul 0
39 2021-11-17 03:37:26 George 8
40 2021-11-17 08:31:07 George 7
41 2021-11-18 02:14:45 George 9
42 2021-11-18 12:25:14 Paul 25
43 2021-11-19 03:54:08 John 14
44 2021-11-19 23:07:52 Paul 4
45 2021-11-20 10:29:48 George 12
46 2021-11-20 15:54:49 John 22
47 2021-11-21 07:08:04 John 23
48 2021-11-22 00:51:01 John 28
49 2021-11-22 05:03:36 John 8
$ cat -n test1.csv | (head; echo; tail)
1 date,tag,count
2 2021-10-25 09:25:00,George,14
3 2021-10-25 22:47:36,Paul,16
4 2021-10-26 07:45:27,George,20
5 2021-10-26 20:43:36,Paul,25
6 2021-10-27 02:09:55,Paul,27
7 2021-10-27 17:31:10,John,7
8 2021-10-28 21:04:15,Ringo,10
9 2021-10-28 22:28:52,Ringo,26
10 2021-10-29 13:55:21,Paul,15
42 2021-11-17 08:31:07,George,7
43 2021-11-18 02:14:45,George,9
44 2021-11-18 12:25:14,Paul,25
45 2021-11-19 03:54:08,John,14
46 2021-11-19 23:07:52,Paul,4
47 2021-11-20 10:29:48,George,12
48 2021-11-20 15:54:49,John,22
49 2021-11-21 07:08:04,John,23
50 2021-11-22 00:51:01,John,28
51 2021-11-22 05:03:36,John,8