Professional Documents
Culture Documents
Ch2 PDF Slides
Ch2 PDF Slides
Introduction to
other file types
Importing Data in Python I
Pickled files
File type native to Python
Motivation: many datatypes for which it isnt
obvious how to store them
Pickled files are serialized
Serialize = convert object to bytestream
Importing Data in Python I
Pickled files
In [1]: import pickle
In [3]: print(data)
{'peaches': 13, 'apples': 4, 'oranges': 11}
Importing Data in Python I
In [4]: print(data.sheet_names)
['1960-1966', '1967-1974', '1975-2011']
Youll learn:
How to customize your import
Skip rows
Import certain columns
Change column names
IMPORTING DATA IN PYTHON I
Lets practice!
IMPORTING DATA IN PYTHON I
Importing
SAS/Stata files
using pandas
Importing Data in Python I
SAS files
Used for:
Advanced analytics
Multivariate analysis
Business intelligence
Data management
Predictive analytics
Standard for computational analysis
Importing Data in Python I
Lets practice!
IMPORTING DATA IN PYTHON I
Importing
HDF5 files
Importing Data in Python I
HDF5 files
Hierarchical Data Format version 5
Standard for storing large quantities of numerical data
Datasets can be hundreds of gigabytes or terabytes
HDF5 can scale to exabytes
Importing Data in Python I
In [4]: print(type(data))
<class 'h5py._hl.files.File'>
Importing Data in Python I
In [6]: print(type(data['meta']))
<class 'h5py._hl.group.Group'>
Importing Data in Python I
Lets practice!
IMPORTING DATA IN PYTHON I
Importing
MATLAB files
Importing Data in Python I
MATLAB
Matrix Laboratory
Industry standard in engineering and science
Data saved as .mat files
Importing Data in Python I
In [4]: print(type(mat))
<class 'dict'>
In [5]: print(type(mat['x']))
<class 'numpy.ndarray'>
Lets practice!