Convert csv to sqlite table

in Python with pandas and sqlite3

What you need to install


Then simply run supported functionality. Here is the sample code

if __name__ == "__main__":
import sqlite3
import pandas as pd

# load data
df = pd.read_csv('../resources/hgnc_data.txt', sep='\t')

# strip whitespace from headers
df.columns = df.columns.str.strip()

con = sqlite3.connect("hgnc.db")

# drop data into database
df.to_sql("hgnc_data", con)


And we’re good to go.


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store