Book Image

Python Data Analysis Cookbook

By : Ivan Idris
Book Image

Python Data Analysis Cookbook

By: Ivan Idris

Overview of this book

Data analysis is a rapidly evolving field and Python is a multi-paradigm programming language suitable for object-oriented application development and functional design patterns. As Python offers a range of tools and libraries for all purposes, it has slowly evolved as the primary language for data science, including topics on: data analysis, visualization, and machine learning. Python Data Analysis Cookbook focuses on reproducibility and creating production-ready systems. You will start with recipes that set the foundation for data analysis with libraries such as matplotlib, NumPy, and pandas. You will learn to create visualizations by choosing color maps and palettes then dive into statistical data analysis using distribution algorithms and correlations. You’ll then help you find your way around different data and numerical problems, get to grips with Spark and HDFS, and then set up migration scripts for web mining. In this book, you will dive deeper into recipes on spectral analysis, smoothing, and bootstrapping methods. Moving on, you will learn to rank stocks and check market efficiency, then work with metrics and clusters. You will achieve parallelism to improve system performance by using multiple threads and speeding up your code. By the end of the book, you will be capable of handling various data analysis techniques in Python and devising solutions for problem scenarios.
Table of Contents (23 chapters)
Python Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Glossary
Index

NumPy


The following creates a NumPy array with evenly spaced values within a specified range:

numpy.arange([start,] stop[, step,], dtype=None)

The following argument returns the indices that would sort the input array:

numpy.argsort(a, axis=-1, kind='quicksort', order=None)

The following creates a NumPy array from an array-like sequence, such as a Python list:

numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)

The following argument calculates the dot product of two arrays:

numpy.dot(a, b, out=None)

The following argument returns the identity matrix:

numpy.eye(N, M=None, k=0, dtype=<type 'float'>)

The following argument loads NumPy arrays or pickled objects from .npy, .npz or pickles. A memory-mapped array is stored in the filesystem and doesn't have to be completely loaded in memory. This is especially useful for large arrays:

numpy.load(file, mmap_mode=None)

The following argument loads data from a text file into a NumPy array:

numpy.loadtxt(fname, dtype=<type 'float'>, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0)

The following calculates the arithmetic mean along the given axis:

numpy.mean(a, axis=None, dtype=None, out=None, keepdims=False)

The following argument calculates the median along the given axis:

numpy.median(a, axis=None, out=None, overwrite_input=False)

The following creates a NumPy array of specified shape and data type, containing ones:

numpy.ones(shape, dtype=None, order='C')

The following performs a least squares polynomial fit:

numpy.polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False)

The following changes the shape of a NumPy array:

numpy.reshape(a, newshape, order='C')

The following argument saves a NumPy array to a file in the NumPy .npy format:

numpy.save(file, arr)

The following argument saves a NumPy array to a text file:

numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', footer='', comments='# ')

The following argument sets printing options:

numpy.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, suppress=None, nanstr=None, infstr=None, formatter=None)

The following argument returns the standard deviation along the given axis:

numpy.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False)

The following selects array elements from input arrays based on a Boolean condition:

numpy.where(condition, [x, y])

The following creates a NumPy array of specified shape and data type, containing zeros:

numpy.zeros(shape, dtype=float, order='C')