How to export CSV file to database with Python


Pandas and SQLAlchemy offer powerful conversions between CSV files and tables in databases. Here is a small example:

import pandas as pd
from sqlalchemy import create_engine

df = pd.read_csv('mydata.csv')

engine = create_engine('sqlite:///mydata.db')
df.to_sql('mytable', engine)

Read more:

,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.