Skip to content

Instantly share code, notes, and snippets.

@JoeThunyathep
Created February 21, 2022 20:11
Show Gist options
  • Save JoeThunyathep/77799013f75a89f401a74acd2bf9f338 to your computer and use it in GitHub Desktop.
Save JoeThunyathep/77799013f75a89f401a74acd2bf9f338 to your computer and use it in GitHub Desktop.
# Import Module
import pandas as pd
from sqlalchemy import create_engine
# Get data using Pandas
df = pd.read_html('https://www.stuttgart-airport.com/security-wait-times/')
# Some minor data cleaning
df = df[0]
df['Wait times'] = df['Wait times'].str.replace(r'\D', '')
df['Wait times'] = pd.to_numeric(df['Wait times'], errors='coerce').astype('float')
df = df.set_index('Terminal').T
# Connect to database
host = '...'
port = '...'
db = '...'
user = '...'
pasw = '...'
engine = create_engine(f"postgresql+psycopg2://{user}:{pasw}@{host}:{port}/{db}")
# Save to Database
table_name = '...'
df.to_sql(table_name, engine,if_exists='append',index=False,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment