Skip to content

Instantly share code, notes, and snippets.

@xescuder
Created January 16, 2024 17:45
Show Gist options
  • Save xescuder/fd764cd82b28b1e8dd75c99c7b3d977a to your computer and use it in GitHub Desktop.
Save xescuder/fd764cd82b28b1e8dd75c99c7b3d977a to your computer and use it in GitHub Desktop.
Load CSV into Table
import os
from pathlib import Path
from sqlalchemy import create_engine
import pandas as pd
from trading_data_pipeline.config import AppConfig
config = AppConfig(os.environ)
connection_url = config.get_postgres_uri()
db = create_engine(connection_url)
conn = db.connect()
csv_path = os.path.join(str(Path(__file__).parent.parent), 'resources', 'sectors_etfs.csv')
data = pd.read_csv(csv_path)
data['type'] = 'SECTOR_ETF'
data.to_sql('instruments', conn, if_exists='append', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment