April 2015
Beginner to intermediate
504 pages
8h 36m
English
pandas can read data from any SQL databases that support Python data adapters, that respect the Python DB-API. Reading is performed using the pandas.io.sql.read_sql() function and writing to SQL databases using the .to_sql() method of DataFrame.
As an example of writing, the following reads the stock data from msft.csv and aapl.csv. It then makes a connection to a SQLite3 database file. If the file does not exist, it creates it on the fly. It then writes the MSFT data to a table named STOCK_DATA. If the table did not exist, it is created. If it exists, all the data is replaced with the MSFT data. It then appends the AAPL stock data to that table:
In [33]: # reference SQLite import sqlite3 # read in the ...
Read now
Unlock full access