Member-only story

Convert csv to sqlite table

Donald Le
Nov 17, 2020

--

in Python with pandas and sqlite3

What you need to install

sqlite3
pandas

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)

con.close()

And we’re good to go.

~~PEACE~~

--

--

Donald Le
Donald Le

Written by Donald Le

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

No responses yet