Python for Data Analysis
Python Basics
Import Conventions
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns impo...
Python Data Structures, Functions and Files
Data Structures Tuples A tuple is a fixed-length, immutable sequence. tup = (4, 5, 6) tup = 4, 5,...
Dictionary and Set
dict Dictionaries are sometimes called hash maps or associative arrays. A dictionary stores a col...
Built-in Sequence Functions
Built-in Sequence Functions enumerate() enumerate returns a sequence of (i, value) in tuples. ind...
List, Set, Dictionary Comprehensions
Basic Form [expression for value in collection if condition] result = [] for value in collection:...
Functions
Functions def func(x): return something Namespaces, Score, and Local Functions Functions can a...
Errors and Exception Handling
Value Error float("1.2345") 1.2345 float("something") ValueError: could not convert string to flo...
Files and the Operating System
open() path = 'examples/segismundo.txt' f = open(path, encoding = 'utf=8') for line in f: pri...
Bytes and Unicode with Files
The default behavior for python files is text mode. This contrasts with binary mode, which you ca...
NumPy
NumPy Basics: Arrays and Vectorized Computation
NumPy NumPy is short for Numerical Python. import numpy as np data = np.array([[1.5, -0.1, 3], [...
NumPy: Pseudorandom Number Generation and Universal Functions
Pseudorandom Number Generation samples = np.random.standard_normal(size=(4,4)) samples array([[ ...
NumPy: Array-Oriented Programming
Array-Oriented Programming Suppose we want to evaluate a function sqrt(x^2 +y^2) across a regular...
NumPy: Linear Algebra
Linear Algebra x = np.array([1, 2, 3], [4, 5, 6]) y = np.array([6, 23], [-1, 7], [8, 9]) np.dot(...
Pandas
Pandas Part I: Series and DataFrame
Series import numpy as np import pandas as pd # A Series is a one-dimensional array-like object ...
Pandas Part II: Essential Functionality
Reindexing Series reindex creates a new object with the values arranged to align with the new ind...
Pandas Part III. Arithmetic, Data Alignment, Mapping, Sorting etc.
Arithmetic and Data Alignment s1 = pd.Series([7.3, -2.5, 3.4, 1.5], index=['a', 'c', 'd', 'e']) s...
Pandas Part IV: Summarizing and Computing Descriptive Statistics
Basic Functions df = pd.DataFrame([[1.4, np.nan], [7.1, -4.5], [np.nan, np.nan], [0.75, -1.3]], i...
Pandas Part V: Data Loading, Storage, and File Formats
Reading and Writing Data in Text Format Function Description read_csv csv read_clipboard...