Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
JMiltner97 committed Jan 28, 2024
1 parent d0fc300 commit bb6a72d
Show file tree
Hide file tree
Showing 2 changed files with 1,308 additions and 0 deletions.
22 changes: 22 additions & 0 deletions exercises/exercise5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import zipfile
import pandas as pd
from urllib.request import urlretrieve
from sqlalchemy import create_engine

data = "https://gtfs.rhoenenergie-bus.de/GTFS.zip"
urlretrieve(data, "GTFS.zip")
with zipfile.ZipFile("GTFS.zip", 'r') as zip:
zip.extract("stops.txt", '.')
df = pd.read_csv("stops.txt")
df = df['zone_id'] == 2001
df['valid_coordinates'] = (
(df['stop_lat'] >= -90) & (df['stop_lat'] <= 90) &
(df['stop_lon'] >= -180) & (df['stop_lon'] <= 180)
)
df = df[df['valid_coordinates']]


df = df.filter(items=['stop_id', 'stop_name', 'stop_lat', 'stop_lon', 'zone_id'])
#print(df)
engine = create_engine("sqlite:///gtfs.sqlite")
df.to_sql(name="stops", con=engine, if_exists="replace", index=False)
Loading

0 comments on commit bb6a72d

Please sign in to comment.