Created
February 21, 2022 20:11
-
-
Save JoeThunyathep/77799013f75a89f401a74acd2bf9f338 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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