Skip to main content

No project description provided

Project description

df_to_sql

DataFrame to SQL facilitates importing Pandas DataFrames into SQL databases. It automates table and type migrations and deduplication of records.

Usage

from df_to_sql import DFToSQL
from df_to_sql import date_regexes
from df_to_sql import number_regexes

date_regexes.append(r'^[0-9]{4}-[0-9]{2}-[0-9]{2}$')

dts = DFToSQL(date_regexes=date_regexes)

if 'sqlite.db' in os.listdir('.'): os.remove('./sqlite.db')

sqlite3.connect('sqlite.db')

sl_engine = sa.create_engine('sqlite:///sqlite.db')

for _ in range(0, 10):

    df = pd.util.testing.makeMixedDataFrame()

    dts.integrate(df=df, table_name='table_name', schema='main', engine=sl_engine)

sl_engine = sa.create_engine('sqlite:///sqlite.db')

df = pd.read_sql_table('table_name', con=sl_engine)

print(df.dtypes)

print(df.shape)

The imported table has these properties:

print(df.dtypes)
a             int64
b             int64
c            object
d    datetime64[ns]

print(df.shape)
dtype: object
(5, 4)

Install

pip install df_to_sql

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

df_to_sql-2.0.0.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

df_to_sql-2.0.0-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page