Introduction to Importing Data in Python
Learn to load text, CSV, Excel, SAS, Stata, HDF5 and MATLAB files into Python, then query relational databases with SQL and pandas.
Getting data into Python has to happen before any cleaning, plotting or modeling, and there are many ways to do it. You read plain text and CSV files, load Excel spreadsheets and files written by programs like SAS, Stata and MATLAB, and pull records out of a relational database with SQL, so each source ends up as an array or DataFrame ready for analysis.
What You Will Achieve
- Load a CSV or plain text file as an array or DataFrame, setting the delimiter, header rows and column types
- Find the sheets in an Excel workbook and import the one you need with custom settings
- Get the data out of SAS, Stata, HDF5, MATLAB and pickled files and into a form Python can work with
- Query an SQLite database from Python, filtering and sorting records and combining related tables into one DataFrame
Program Overview
Flat Files in NumPy and pandas
Why flat files are such a common way to store data, and how to read them line by line or with two core packages.
- Reading text files whole and line by line
- Flat file structure and the Zen of Python
- NumPy imports with custom delimiters and datatypes
- pandas imports as DataFrames
Spreadsheets and Other File Types
Formats that are not flat, each opened with the package or function suited to it.
- Pickled files
- Listing and importing Excel sheets
- SAS7BDAT and Stata files with pandas
- HDF5 with h5py and MATLAB .mat files
Relational Databases and SQL Queries
The relational model and how to query a database from Python, first through an engine and then directly with pandas.
- Creating a database engine and listing its tables
- SELECT queries with WHERE and ORDER BY
- Running queries directly with pandas
- INNER JOIN across related tables
Certificate Awarded (Paid)
Complete the course to earn it.
Job Outlook
Importing data is the first step in data analysis and data science work wherever information sits in flat files, spreadsheets, statistical software files or relational databases.
Good for: Analysts and aspiring data scientists who need to load data stored in many formats, including spreadsheets, statistics files and SQL databases.
Keep in mind: Despite the beginner label, the first chapter expects earlier practice with NumPy and pandas, and the database lessons are built around SQLite through SQLAlchemy.
Bottom line: Its strength is breadth, covering import methods for many file types and finishing with joined SQL queries loaded straight into pandas.
Frequently Asked Questions
Which Python packages do the lessons use?
Flat files are imported with NumPy and pandas, SAS and Stata files are read with pandas functions such as read_stata, HDF5 files are opened with h5py, and SQLAlchemy creates the engine that connects Python to a database.
What is an HDF5 file?
HDF5 is a hierarchical format for storing large quantities of numerical data. The lessons open an HDF5 file with h5py, look at how it is organized and extract the stored data into Python.
Which database does the SQL chapter work with?
The exercises connect to an SQLite database through a SQLAlchemy engine. The chapter explains the relational model, then builds queries step by step and shows how pandas can run a query and return the result as a DataFrame.


There are no reviews yet.