Pandas snippets
Jump to navigation
Jump to search
DataFrame to JSON for SQL
This will do it for all columns all rows.
for i in df.columns: df[i] = [json.dumps(x) for x in df[i]] df.to_sql(name='fb1', con=cnx, index=False)
Assuming dataframe df
import pandas import sqlite3 for i in df.columns: df[i] = [json.dumps(x) for x in df[i]] cnx = sqlite3.connect(f"db.sqlite3") df.to_sql(name='table1', con=cnx, index=False)