forked from dtxe/DSI_git_assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyze.py
More file actions
33 lines (24 loc) · 713 Bytes
/
Analyze.py
File metadata and controls
33 lines (24 loc) · 713 Bytes
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
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
def import_data():
"""
Import data from the TTC Bus Delay dataset
"""
return pd.read_csv('ttc-bus-delay-data-2023.csv')
def compute_avg_delay(data, group_by: str = 'Route'):
"""
Compute the average delay aggregated by specified column
"""
return data.groupby('Route')['Min Delay'].mean().reset_index()
def main():
"""
Main function
"""
data = import_data()
avg_delay = compute_avg_delay(data, group_by='Route')
plt.hist(avg_delay['Min Delay'], bins=30)
plt.title('Average Delay Distribution')
plt.xlabel('Average Delay (minutes)')
if __name__ == '__main__':
main()