-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakedata.py
More file actions
107 lines (95 loc) · 2.42 KB
/
makedata.py
File metadata and controls
107 lines (95 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import csv
from uuid import uuid4
PEOPLE = [
(
"John",
"Doe",
"Fishing,Biking",
"12345",
"jodo@example.com",
"1, Sample Street\n123ABC Stonehenge",
),
(
"Jane",
"Doe",
"Biking,Videogames",
"12345",
"jado@example.com",
"1, Sample Street\n123ABC Stonehenge",
),
(
"Karl",
"Mustermann",
"Fitness,Cooking,Football",
"11223",
"musti@example.com",
"2A Schlossallee\n123 Brett",
),
(
"Anna",
"Musterfrau",
"Häkeln,Cooking",
"11223",
"musti@example.com",
"22 Ostbahnhof\n111 Brett",
),
]
HOBBIES = {
"Fishing",
"Biking",
"Videogames",
"Fitness",
"Cooking",
"Reading",
"Football",
"Häkeln",
}
def make_split_rows():
"""
Creates a more complex example for the "collections" exercise
"""
with open("slides/_static/collections.csv", "w") as outfile:
rows = []
rows.append(["First Name", "Last Name", "Hobbies"])
rows.append(["Phone", "email", "Address"])
for person in PEOPLE:
rows.append(person[:3])
rows.append(person[3:])
writer = csv.writer(outfile)
writer.writerows(rows)
def make_lookup_table():
"""
Creates data which can be used for the encoding & merging exercise
"""
from random import choice
cities = [
(uuid4(), "São Paulo", "Yellow"),
(uuid4(), "Bogotá", "Yellow"),
(uuid4(), "澳门特别行政区", "Blue"),
(uuid4(), "犬山市", "Red"),
(uuid4(), "Mersch", "Blue"),
]
with open("slides/_static/city_lookup_people.csv", "w") as outfile:
writer = csv.writer(outfile)
header = [
"First Name",
"Last Name",
"Hobbies",
"Phone #",
"email",
"Address",
"City ID",
]
writer.writerow(header)
for input_row in PEOPLE:
city = choice(cities)
city_id = city[0]
output_row = input_row + (city_id,)
writer.writerow(output_row)
with open("slides/_static/city_lookup_cities.csv", "w") as outfile:
writer = csv.writer(outfile)
header = ["id", "name", "team"]
writer.writerow(header)
writer.writerows(cities)
if __name__ == "__main__":
make_lookup_table()