-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstation_explorer.py
More file actions
60 lines (47 loc) · 1.92 KB
/
station_explorer.py
File metadata and controls
60 lines (47 loc) · 1.92 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
import pickle
import numpy as np
import pandas as pd
data = pd.read_pickle('dataframe.pkl')
class StationExplorer :
def __init__(self):
self.data = data
def get_km(self,station,line):
"""
get the kilometer number of a station on the line.
Parameters:
station (str): The name of the station.
line (double): The line number.
Returns:
float: The kilometer number of the station on the line.
"""
return self.data.loc[(self.data['Stop name'] == station) & (self.data['Line'] == line), 'KM'].iloc[0]
def served_stations(self,line):
"""
get the stations of a line for a given line number
Parameters:
line (double): The line number.
Returns:
served_stations (array of strings): The stations of the line that are served by the trainline.
"""
served_stations = self.data[self.data['Line'] == line]['Stop name'].unique()
return served_stations
def ordered_served_stations(self,line):
"""
order the served stations of a line
Parameters:
line (double): The line number.
Returns:
ordered_served_stations (array of strings): The stations of the line in order of being served by the trainline.
"""
served_stations = self.served_stations(line)
ordered_served_stations = sorted(served_stations, key = lambda station: self.get_km(station, line))
return ordered_served_stations
explorer = StationExplorer()
'''
############### DESCRIPTIVE INFORMATION ############################
print(pd.Categorical(data['Station abbreviation']).categories) #811 Stations
print(pd.Categorical(data['Stop name']).categories) #again 811 Stations
print(pd.Categorical(data['Line']).categories) #121 Lines
print(pd.Categorical(data['Platform type']).categories) #5 Types
print(pd.Categorical(data['Step']).categories) #4 Types
'''