-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpro2.py
More file actions
69 lines (56 loc) · 1.81 KB
/
Copy pathpro2.py
File metadata and controls
69 lines (56 loc) · 1.81 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
import csv
import os
import errno
Data_Frame = []
infile = open('C:\\Users\\ankes\\Documents\\Python Scripts\\uber.csv', 'r')
rows = 0
colendcount = 0
for row in csv.reader(infile, delimiter = ','):
try:
xyz = row[rows]
except IndexError:
if colendcount < 1:
print("Number of columns in Data Frame: ", rows)
colendcount += 1
rows += 1
Data_Frame.append(row)
print("Number of rows in Data Frame: ",rows)
#for row in Data_Frame:
# print (row,"\n")
#print(Data_Frame)
# Segregating Data Frames based on trip completion.
tripcomplete = []
tripdroped = []
carshortage = []
rows = 0
for row in Data_Frame:
if Data_Frame[rows][3] == 'Trip Completed':
tripcomplete.append(row)
elif Data_Frame[rows][3] == 'Cancelled':
tripdroped.append(row)
else:
carshortage.append(row)
rows += 1
# Created new folder for keeping intermediate data frames
try:
os.mkdir('C:\\Users\\ankes\\Documents\\Python Scripts\\uber\\')
except OSError:
print("uber folder exists in directory!")
# Writing data frames to csv
outfile = open('C:\\Users\\ankes\\Documents\\Python Scripts\\uber\\tripcompleted.csv', 'w', newline ='')
writer = csv.writer(outfile)
for row in tripcomplete:
writer.writerow(row)
outfile.close
outfile = open('C:\\Users\\ankes\\Documents\\Python Scripts\\uber\\tripdropped.csv', 'w', newline ='')
writer = csv.writer(outfile)
for row in tripdroped:
writer.writerow(row)
outfile.close
outfile = open('C:\\Users\\ankes\\Documents\\Python Scripts\\uber\\carshortage.csv', 'w', newline ='')
writer = csv.writer(outfile)
for row in carshortage:
writer.writerow(row)
outfile.close
#print (tripcomplete)
# Extracting columns needed for plot in single dimension list[]