Running Pylint gives us these corrections: (the first ten, highlighted bold, got corrected)
PS C:\Users\Administrator\Desktop\SBB\SBB-Platform-Manager> pylint station_explorer.py
************* Module station_explorer
station_explorer.py:11:0: C0301: Line too long (125/100) (line-too-long)
station_explorer.py:1:0: C0114: Missing module docstring (missing-module-docstring)
station_explorer.py:8:0: W0106: Expression "pd.Categorical(data['Station abbreviation']).categories" is assigned to nothing (expression-not-assigned)
station_explorer.py:9:0: W0106: Expression "pd.Categorical(data['Stop name']).categories" is assigned to nothing (expression-not-assigned)
station_explorer.py:10:0: W0106: Expression "pd.Categorical(data['Line']).categories" is assigned to nothing (expression-not-assigned)
station_explorer.py:11:0: W0106: Expression "pd.Categorical(data['Platform type']).categories" is assigned to nothing (expression-not-assigned)
station_explorer.py:12:0: W0106: Expression "pd.Categorical(data['Step']).categories" is assigned to nothing (expression-not-assigned)
station_explorer.py:31:0: C0116: Missing function or method docstring (missing-function-docstring)
station_explorer.py:38:6: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
station_explorer.py:3:0: C0411: standard import "import pickle" should be placed before "import numpy as np" (wrong-import-order)
station_explorer.py:3:0: W0611: Unused import pickle (unused-import)
Your code has been rated at 4.50/10
Fixed Code:
Libraries:
- pickle: Used for loading pickled data.
- numpy (np): Used for numerical operations.
- pandas (pd): Used for data manipulation and analysis.
"""
import pickle
import numpy as np
import pandas as pd
data = pd.read_pickle('dataframe.pkl')
############### 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
#################### EXPOLRE DATA #################################
# Print all existing train line numbers
print('These are the numbers of the existing train lines you can explore:')
possible_line_numbers = np.unique(data['Line'])
print(possible_line_numbers)
print()
# Ask the user to input the line they want to know the stations of
# Test with e.g. "600"
line_number = int(input("Input the number of the train line you want to know the stations of: "))
# Pick only the served stations from the dataframe
served_stations = data[data['Line'] == line_number]['Stop name'].unique()
# Define function to get the km number of the station on the line
def get_km(station):
"""
Get the kilometer number of a station on the line.
Parameters:
station (str): The name of the station.
Returns:
float: The kilometer number of the station on the line.
"""
return data.loc[data['Stop name'] == station, 'KM'].iloc[0]
# Order the served stations of the line
served_stations = sorted(served_stations, key = get_km)
#Return How Many different linies exist between two spesific station
def get_user_input():
print("Enter the names of two stations to find the distance and number of connecting lines between them.")
station1 = input("Enter the first station name: ")
station2 = input("Enter the second station name: ")
return station1, station2
# Show the ordered served stations on the line
print(f"The train line {line_number} passes the stations: ")
print(served_stations)```