Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning Pandas
  • Table Of Contents Toc
Learning Pandas

Learning Pandas

By : Michael Heydt
4.2 (10)
close
close
Learning Pandas

Learning Pandas

4.2 (10)
By: Michael Heydt

Overview of this book

If you are a Python programmer who wants to get started with performing data analysis using pandas and Python, this is the book for you. Some experience with statistical analysis would be helpful but is not mandatory.
Table of Contents (14 chapters)
close
close
13
Index

Reading and writing from/to SQL databases


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 stock data from CSV
   msft = pd.read_csv("data/msft.csv")
   msft["Symbol"]="MSFT"
   aapl = pd.read_csv("data/aapl.csv")
   aapl["Symbol"]="AAPL"

   # create connection
   connection = sqlite3.connect("data/stocks.sqlite")
   # .to_sql...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning Pandas
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon