Pandas Cookbook

Author: Theodore Petrou  

Publisher: Packt Publishing‎

Publication year: 2017

E-ISBN: 9781784393342

P-ISBN(Paperback): 9781784393878

Subject: TN919.5 数据处理系统及设备;TP274 数据处理、数据处理系统

Language: ENG

Access to resources Favorite

Disclaimer: Any content in publications that violate the sovereignty, the constitution or regulations of the PRC is not accepted or approved by CNPIEC.

Chapter

Preface

Chapter 1: Pandas Foundations

Introduction

Dissecting the anatomy of a DataFrame

Getting ready

How to do it...

How it works...

There's more...

See also

Accessing the main DataFrame components

Getting ready

How to do it...

How it works...

There's more...

See also

Understanding data types

Getting ready

How to do it...

How it works...

There's more...

See also

Selecting a single column of data as a Series

Getting ready

How to do it...

How it works...

There's more...

See also

Calling Series methods

Getting ready

How to do it...

How it works...

There's more...

See also

Working with operators on a Series

Getting ready

How to do it...

How it works...

There's more...

See also

Chaining Series methods together

Getting ready

How to do it...

How it works...

There's more...

Making the index meaningful

Getting ready

How to do it...

How it works...

There's more...

See also

Renaming row and column names

Getting ready

How to do it...

How it works...

There's more...

Creating and deleting columns

Getting ready

How to do it...

How it works...

There's more...

See also

Essential Chapter 2: DataFrame Operations

Introduction

Selecting multiple DataFrame columns

Getting ready

How to do it...

How it works...

There's more...

Selecting columns with methods

Getting ready

How it works...

How it works...

There's more...

See also

Ordering column names sensibly

Getting ready

How to do it...

How it works...

There's more...

See also

Operating on the entire DataFrame

Getting ready

How to do it...

How it works...

There's more...

Chaining DataFrame methods together

Getting ready

How to do it...

How it works...

There's more...

See also

Working with operators on a DataFrame

Getting ready

How to do it...

How it works...

There's more...

See also

Comparing missing values

Getting ready

How to do it...

How it works...

There's more...

Transposing the direction of a DataFrame operation

Getting ready

How to do it...

How it works...

There's more...

See also

Determining college campus diversity

Getting ready

How to do it...

How it works...

There's more...

See also

Chapter 3: Beginning Data Analysis

Introduction

Developing a data analysis routine

Getting ready

How to do it...

How it works...

There's more...

Data dictionaries

See also

Reducing memory by changing data types

Getting ready

How to do it...

How it works...

There's more...

See also

Selecting the smallest of the largest

Getting ready

How to do it...

How it works...

There's more...

Selecting the largest of each group by sorting

Getting ready

How to do it...

How it works...

There's more...

Replicating nlargest with sort_values

Getting ready

How to do it...

How it works...

There's more...

Calculating a trailing stop order price

Getting ready

How to do it...

How it works...

There's more...

See also

Chapter 4: Selecting Subsets of Data

Introduction

Selecting Series data

Getting ready

How to do it...

How it works...

There's more...

See also

Selecting DataFrame rows

Getting ready

How to do it...

How it works...

There's more...

See also

Selecting DataFrame rows and columns simultaneously

Getting ready

How to do it...

How it works...

There's more...

Selecting data with both integers and labels

Getting ready

How to do it...

How it works...

There's more...

See also

Speeding up scalar selection

Getting ready

How to do it...

How it works...

There's more...

Slicing rows lazily

Getting ready

How to do it...

How it works...

There's more...

Slicing lexicographically

Getting ready

How to do it...

How it works...

There's more...

Chapter 5: Boolean Indexing

Introduction

Calculating boolean statistics

Getting ready

How to do it...

How it works...

There's more...

See also

Constructing multiple boolean conditions

Getting ready

How to do it...

How it works...

There's more...

See also

Filtering with boolean indexing

Getting ready

How to do it...

How it works...

There's more...

See also

Replicating boolean indexing with index selection

Getting ready

How to do it...

How it works...

There's more...

Selecting with unique and sorted indexes

Getting ready

How to do it...

How it works...

There's more...

See also

Gaining perspective on stock prices

Getting ready

How to do it...

How it works...

There's more...

See also

Translating SQL WHERE clauses

Getting ready

How to do it...

How it works...

There's more...

See also

Determining the normality of stock market returns

Getting ready

How to do it...

How it works...

There's more...

See also

Improving readability of boolean indexing with the query method

Getting ready

How to do it...

How it works...

There's more...

See also

Preserving Series with the where method

Getting ready

How to do it...

How it works...

There's more...

See also

Masking DataFrame rows

Getting ready

How to do it...

How it works...

There's more...

See also

Selecting with booleans, integer location, and labels

Getting ready

How to do it...

How it works...

There's more...

See also

Chapter 6: Index Alignment

Introduction

Examining the Index object

Getting ready

How to do it...

How it works...

There's more...

See also

Producing Cartesian products

Getting ready

How to do it...

How it works...

There's more...

See also

Exploding indexes

Getting ready

How to do it...

How it works...

There's more...

Filling values with unequal indexes

Getting ready

How to do it...

How it works...

There's more...

Appending columns from different DataFrames

Getting ready

How to do it...

How it works...

There's more...

See also

Highlighting the maximum value from each column

Getting ready

How to do it...

How it works...

There's more...

See also

Replicating idxmax with method chaining

Getting ready

How to do it...

How it works...

There's more...

Finding the most common maximum

Getting ready

How to do it...

How it works...

There's more...

Chapter 7: Grouping for Aggregation, Filtration, and Transformation

Introduction

Defining an aggregation

Getting ready

How to do it...

How it works...

There's more...

See also

Grouping and aggregating with multiple columns and functions

Getting ready

How to do it...

How it works...

There's more...

Removing the MultiIndex after grouping

Getting ready

How to do it...

How it works...

There's more...

Customizing an aggregation function

Getting ready

How to do it...

How it works...

There's more...

Customizing aggregating functions with *args and **kwargs

Getting ready

How to do it...

How it works...

There's more...

See also

Examining the groupby object

Getting ready

How to do it...

How it works...

There's more...

See also

Filtering for states with a minority majority

Getting ready

How to do it...

How it works...

There's more...

See also

Transforming through a weight loss bet

Getting ready

How to do it...

How it works...

There's more...

See also

Calculating weighted mean SAT scores per state with apply

Getting ready

How to do it...

How it works...

There's more...

See also

Grouping by continuous variables

Getting ready

How to do it...

How it works...

There's more...

See also

Counting the total number of flights between cities

Getting ready

How to do it...

How it works...

There's more...

See also

Finding the longest streak of on-time flights

Getting ready

How to do it...

How it works...

There's more...

See also

Chapter 8: Restructuring Data into a Tidy Form

Introduction

Tidying variable values as column names with stack

Getting ready

How to do it...

How it works...

There's more...

See also

Tidying variable values as column names with melt

Getting ready

How to do it...

How it works...

There's more...

See also

Stacking multiple groups of variables simultaneously

Getting ready

How to do it...

How it works...

There's more...

See also

Inverting stacked data

Getting ready

How to do it...

How it works...

There's more...

See also

Unstacking after a groupby aggregation

Getting ready

How to do it...

How it works...

There's more...

See also

Replicating pivot_table with a groupby aggregation

Getting ready

How to do it...

How it works...

There's more...

Renaming axis levels for easy reshaping

Getting ready

How to do it...

How it works...

There's more...

Tidying when multiple variables are stored as column names

Getting ready...

How to do it...

How it works...

There's more...

See also

Tidying when multiple variables are stored as column values

Getting ready

How to do it...

How it works...

There's more...

See also

Tidying when two or more values are stored in the same cell

Getting ready...

How to do it..

How it works...

There's more...

Tidying when variables are stored in column names and values

Getting ready

How to do it...

How it works...

There's more...

Tidying when multiple observational units are stored in the same table

Getting ready

How to do it...

How it works...

There's more...

See also

Chapter 9: Combining Pandas Objects

Introduction

Appending new rows to DataFrames

Getting ready

How to do it...

How it works...

There's more...

Concatenating multiple DataFrames together

Getting ready

How to do it...

How it works...

There's more...

Comparing President Trump's and Obama's approval ratings

Getting ready

How to do it...

How it works...

There's more...

See also

Understanding the differences between concat, join, and merge

Getting ready

How to do it...

How it works...

There's more...

See also

Connecting to SQL databases

Getting ready

How to do it...

How it works...

There's more...

See also

Chapter 10: Time Series Analysis

Introduction

Understanding the difference between Python and pandas date tools

Getting ready

How to do it...

How it works...

There's more...

See also

Slicing time series intelligently

Getting ready

How to do it...

How it works...

There's more...

See also

Using methods that only work with a DatetimeIndex

Getting ready

How to do it...

How it works...

There's more...

See also

Counting the number of weekly crimes

Getting ready

How to do it...

How it works...

There's more...

See also

Aggregating weekly crime and traffic accidents separately

Getting ready

How to do it...

How it works...

There's more...

Measuring crime by weekday and year

Getting ready

How to do it...

How it works...

There's more...

See also

Grouping with anonymous functions with a DatetimeIndex

Getting ready

How to do it...

How it works...

There's more...

See also

Grouping by a Timestamp and another column

Getting ready

How to do it...

How it works...

There's more...

Finding the last time crime was 20% lower with merge_asof

Getting ready

How to do it...

How it works...

There's more...

Chapter 11: Visualization with Matplotlib, Pandas, and Seaborn

Introduction

Getting started with matplotlib

Getting ready

Object-oriented guide to matplotlib

How to do it...

How it works...

There's more...

See also

Visualizing data with matplotlib

Getting ready

How to do it...

How it works...

There's more...

See also

Plotting basics with pandas

Getting ready

How to do it..

How it works...

There's more...

See also

Visualizing the flights dataset

Getting ready

How to do it...

How it works...

See also

Stacking area charts to discover emerging trends

Getting ready

How to do it...

How it works...

There's more...

Understanding the differences between seaborn and pandas

Getting ready

How to do it...

How it works...

See also

Doing multivariate analysis with seaborn Grids

Getting ready

How to do it...

How it works...

There's more...

Uncovering Simpson's paradox in the diamonds dataset with seaborn

How to do it...

How it works...

There's more...

Index

The users who browse this book also browse