Skip to content

Commit 1f0875d

Browse files
committed
changed Pandas to read from a csv with the current structure
1 parent 6009647 commit 1f0875d

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

app.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import pandas as pd
44
from flask import Flask, jsonify
55

6-
from data import data
7-
86
app = Flask(__name__)
9-
number_stations = data.number_stations
7+
number_stations = pd.read_csv("./data/number_stations.csv")
8+
109

1110
@app.route('/')
1211
def index():
@@ -20,7 +19,7 @@ def index():
2019
def station_names():
2120
st_df = pd.DataFrame(number_stations)
2221
# Filter the DataFrame columns to retrieve all stations under 'Number Station name'
23-
st_name = st_df['Number Station name']
22+
st_name = st_df['Number']
2423
# If the DataFrame returns a response, convert the Series to a JSON string
2524
f = st_name.to_json()
2625
# Then convert the JSON string to a dict to properly format it when sending the response to the client
@@ -29,12 +28,10 @@ def station_names():
2928

3029
@app.route('/filter_station_names/<name>')
3130
def filer_station_names(name):
32-
print(name)
3331
if name is None:
3432
return jsonify({ 'error': 'Station name cannot be blank' })
35-
fsn_df = pd.DataFrame(number_stations)
3633
# Pass the parameter from the URL and check if it matches against a known station name
37-
f_name = fsn_df[fsn_df['Number Station name'] == name]
34+
f_name = number_stations[number_stations['Name'] == name]
3835
# If the DataFrame returns empty, send an error back to the client
3936
if f_name.empty:
4037
return jsonify({ 'error': 'That station does not exist'})

data/number_stations.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ID,Name,Country,Active Counterparts,Inactive counterparts
2+
E06,English Man 00000,Russia,"S06, M14, F01, F06","E17, G06, V06, V23"

0 commit comments

Comments
 (0)