-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup-db-instructions.py
29 lines (21 loc) · 999 Bytes
/
setup-db-instructions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#Dependencies
import pandas as pd
from sqlalchemy import create_engine
import config
#Extract CSV into DataFrame
restaurants_df = pd.read_csv("../data/cleanDb_Aug_31cuisines.csv")
#Extract CSV into DataFrame
violations_df = pd.read_csv("../data/Violations1.csv")
#Create Database connection
connection_string = f"postgres:{config.password}@localhost:5432/restaurant_db"
engine = create_engine(f'postgresql://{connection_string}')
# Confirm tables
engine.table_names()
#Use pandas to Load csv converted DataFrames into database
restaurants_df.to_sql(name='restaurants', con=engine, if_exists='append', index=False)
#confirm data has been added by quering the table
pd.read_sql_query('select * from restaurants', con=engine).head()
#Use pandas to Load csv converted DataFrames into database
violations_df.to_sql(name='violations', con=engine, if_exists='append', index=False)
#confirm data has been added by quering the table
pd.read_sql_query('select * from violations', con=engine).head()