[Python logging] importing Pandas Dataframe into Sqlite3 and dataframesqlite3

Source: Internet
Author: User

[Python logging] importing Pandas Dataframe into Sqlite3 and dataframesqlite3

Use pandas. io connector to input Sqlite

Import sqlite3 as litefrom pandas. io import sqlimport pandas as pd

According to if_exists, input sqlite in three modes:

The following parameters are available: failed, replace, and append.

 

# Link sqlite Data Sheet cnx = lite. connect ('data. db ') # selecting the region name to be imported into dataframe # The region name should be the same as the region name of the resource to be imported into SQL _df = df.. loc [:, ['column Name a', 'column Name ', 'column Name a'] # import SQL _df data into Table Name Daily_Record # if_exists configure failed to create A new Daily_Record table and import SQL _df data SQL. write_frame (SQL _df, name = 'daily _ Record ', con = cnx) # if_exists select "replace" as the "Daily_Record" table that already exists. # Delete the "Daily_Record" table and re-create the SQL statement that records the "SQL _df" table. write_frame (SQL _df, name = 'daily _ Record ', con = cnx, if_exists = 'replace ') # if_exists: Select appappnd as Daily_Record. The table already has data. Insert the SQL _df data into the SQL statement. write_frame (SQL _df, name = 'daily _ Record ', con = cnx, if_exists = 'append ')

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.