Commit cbecf7f4 authored by Wit, Allard de's avatar Wit, Allard de
Browse files

First of our csv2db command

parent d52f49e9
from pathlib import Path
import pandas as pd
import sqlalchemy as sa
def get_database_engine(sqlite_fname):
dsn = f"sqlite:///{sqlite_fname}"
engine = sa.create_engine(dsn)
return engine
def process_csv(csv_fname, sqlite_fname):
csv_fname = Path(csv_fname).absolute()
sqlite_fname = Path(sqlite_fname).absolute()
df = pd.read_csv(csv_fname)
engine = get_database_engine(sqlite_fname)
with engine.begin() as DBconn:
df.to_sql("csv_data", DBconn, if_exists="replace", index=False)
return df
\ No newline at end of file
from csvtools.csv2db import process_csv
csv_fname = r"c:\temp\US_UFO_sightings.csv"
sqlite_fname = r"c:\temp\US_UFO_sightings.db"
process_csv(csv_fname, sqlite_fname)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment