In [31]:
import csv

t_start=[]
t_end=[]
t_trip = []
filename='/home/jl7333/Citi-Bike/data/201601-data.csv'
with open(filename,'r') as csvfile:
    filereader=csv.reader(csvfile,delimiter=',')
    header=next(filereader)
    for row in filereader:
        start=row[1]
        start=start.split(' ')
        start=start[1]
        start=start.split(':')
        start=start[0]
        start=int(start)
        
        t_start.append(start)
        end=row[2]
        end=end.split(' ')
        end=end[1]
        end=end.split(':')
        end=end[0]
        end=int(end)
        
        t_end.append(end)
        
        t_trip.append((start, end))

In [26]:
bikes_in_use = []
for i in range(24):
    bikes_in_use.append(0)
    
print(bikes_in_use)

for trip in t_trip:
    if trip[0]==trip[1]:
        bikes_in_use[trip[0]]+=1
    else:
        for x in range(trip[0], trip[1]):
            bikes_in_use[x]+=1
        bikes_in_use[trip[1]]+=1


[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

In [30]:
print(bikes_in_use)
import matplotlib.pyplot as plt
plt.plot(range(24), bikes_in_use)
plt.title("number of bicycles used in each hour")
plt.xlabel("hour")
plt.ylabel("Frequency")
plt.show()


[5320, 3278, 1914, 1288, 1253, 3572, 12781, 26205, 50554, 44835, 28250, 28055, 32268, 35164, 37437, 38862, 43650, 56831, 55173, 38618, 24882, 16659, 12466, 7184]

In [ ]:


In [ ]: