-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
174 lines (162 loc) · 6.2 KB
/
main.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#To Do
#-ONLY sort by what columns the user specifies
import csv
import pandas
import os.path
from os import path
input_list=[]
print(f'1:incident_id\n2:case_number\n3:incident_datetime\n4:incident_type_primary\n5:incident_description\n6:clearance_type\n7:address_1\n8:address_2\n9:city\n10:state\n11:zip\n12:country\n13:latitude\n14:longitude\n15:created_at\n16:updated_at\n17:location\n18:hour_of_day\n19:day_of_week\n20:parent_incident_type\n')
while 1:#userInput >= 1 and userInput <= 20:
try:
userInput = int(input("Please specify desired columns.\n"))
except ValueError:
print("Input must be of int type. Ending input loop.")
break
if userInput < 1 or userInput > 20:
print (f'Out of range.\n')
continue
elif userInput in input_list:
print (f'You already entered this column value. Try another.')
continue
elif len(input_list) > 20:
print (f'List is full. Ending input loop.')
break
else:
input_list.append(userInput)
print(f'Printing list...')
print(*input_list)
sortInput = int(input(f'Select the column you would like to sort by.\n'))
if not sortInput in input_list:
print (f'Not in list.')
elif sortInput in input_list:
if sortInput == 1:
print (f"In list. Sorting by incident_id",sortInput)
if sortInput == 2:
print (f"In list. Sorting by case_number",sortInput)
if sortInput == 3:
print (f"In list. Sorting by incident_datetime",sortInput)
if sortInput == 4:
print (f"In list. Sorting by incident_type_primary",sortInput)
if sortInput == 5:
print (f"In list. Sorting by incident_description",sortInput)
if sortInput == 6:
print (f"In list. Sorting by clearance_type",sortInput)
if sortInput == 7:
print (f"In list. Sorting by address_1",sortInput)
if sortInput == 8:
print (f"In list. Sorting by address_2",sortInput)
if sortInput == 9:
print (f"In list. Sorting by city",sortInput)
if sortInput == 10:
print (f"In list. Sorting by state",sortInput)
if sortInput == 11:
print (f"In list. Sorting by zip",sortInput)
if sortInput == 12:
print (f"In list. Sorting by country",sortInput)
if sortInput == 13:
print (f"In list. Sorting by latitude",sortInput)
if sortInput == 14:
print (f"In list. Sorting by longitude",sortInput)
if sortInput == 15:
print (f"In list. Sorting by created_at",sortInput)
if sortInput == 16:
print (f"In list. Sorting by updated_at",sortInput)
if sortInput == 17:
print (f"In list. Sorting by location",sortInput)
if sortInput == 18:
print (f"In list. Sorting by hour_of_day",sortInput)
if sortInput == 19:
print (f"In list. Sorting by day_of_week",sortInput)
if sortInput == 20:
print (f"In list. Sorting by parent_incident_type",sortInput)
# out = pandas.read_csv('Riverside_County_Sheriff_Department.csv')
incident_id = 1
case_number = 2
incident_datetime = 3
incident_type_primary = 4
incident_description = 5
clearance_type = 6
address_1 = 7
address_2 = 8
city = 9
state = 10
zip = 11
country = 12
latitude = 13
longitude = 14
created_at = 15
updated_at = 16
location = 17
hour_of_day = 18
day_of_week = 19
parent_incident_type = 20
#super long brute force if statements
print (f"Creating csv file. One moment.")
print (f'.')
print (f'..')
print (f'...')
if sortInput == 1:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'incident_id', parse_dates=['incident_datetime'])
elif sortInput == 2:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'case_number', parse_dates=['incident_datetime'])
elif sortInput == 3:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'incident_datetime', parse_dates=['incident_datetime'])
elif sortInput == 4:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'incident_type_primary', parse_dates=['incident_datetime'])
elif sortInput == 5:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'incident_description', parse_dates=['incident_datetime'])
elif sortInput == 6:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'clearance_type', parse_dates=['incident_datetime'])
elif sortInput == 7:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'address_1', parse_dates=['incident_datetime'])
elif sortInput == 8:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'address_2', parse_dates=['incident_datetime'])
elif sortInput == 9:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'city', parse_dates=['incident_datetime'])
elif sortInput == 10:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'state', parse_dates=['incident_datetime'])
elif sortInput == 11:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'zip', parse_dates=['incident_datetime'])
elif sortInput == 12:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'country', parse_dates=['incident_datetime'])
elif sortInput == 13:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'latitude', parse_dates=['incident_datetime'])
elif sortInput == 14:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'longitude', parse_dates=['incident_datetime'])
elif sortInput == 15:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'created_at', parse_dates=['incident_datetime'])
elif sortInput == 16:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'updated_at', parse_dates=['incident_datetime'])
elif sortInput == 17:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'location', parse_dates=['incident_datetime'])
elif sortInput == 18:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'hour_of_day', parse_dates=['incident_datetime'])
elif sortInput == 19:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'day_of_week', parse_dates=['incident_datetime'])
elif sortInput == 20:
df = pandas.read_csv('Riverside_County_Sheriff_Department.csv',
index_col = 'parent_incident_type', parse_dates=['incident_datetime'])
df.to_csv('final_output.csv')
if path.exists('final_output.csv'):
print(f"File created successfully.")
else:
print(f"Error, file not created.")