Python Recipes Handbook: A Problem-Solution Approach

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Learn the code to write algorithms, numerical computations, data analysis and much more using the Python language: look up and re-use the recipes for your own Python coding. This book is your handy code cookbook reference. Whether you're a maker, game developer, cloud computing programmer and more, this is a must-have reference for your library. Python Recipes Handbook gives you the most common and contemporary code snippets, using pandas (Python Data Analysis Library), NumPy, and other numerical Python packages. What You'll Learn Code with the pandas (Python Data Analysis Library) Work with the various Python algorithms useful for today's big data analytics and cloud applications Use NumPy and other numerical Python packages and code for doing various kinds of analysis Discover Python's new popular modules, packages, extensions and templates library Who This Book Is For This handy reference is for those with some experience with Python.

Author(s): Joey Bernard
Publisher: Apress
Year: 2016

Language: English
Pages: 123

Contents at a Glance
Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1: Strings and Texts
1-1. Concatenating Strings
Problem
Solution
How It Works
1-2. Comparing Strings
Problem
Solution
How It Works
1-3. Searching for a Substring
Problem
Solution
How It Works
1-4. Getting a Substring
Problem
Solution
How It Works
1-5. Replacing Text Matches
Problem
Solution
How It Works
1-6. Reversing a String
Problem
Solution
How It Works
1-7. Trimming White Space
Problem
Solution
How It Works
1-8. Changing Case
Problem
Solution
How It Works
1-9. Converting to Numbers
Problem
Solution
How It Works
1-10. Iterating Over the Characters of a String
Problem
Solution
How It Works
1-11. Statistics on Texts
Problem
Solution
How It Works
1-12. Encoding Unicode
Problem
Solution
How It Works
1-13. Translation
Problem
Solution
How It Works
Chapter 2: Numbers, Dates, and Times
2-1. Creating Integers
Problem
Solution
How It Works
2-2. Creating Floating Points
Problem
Solution
How It Works
2-3. Rounding Floats to Integers
Problem
Solution
How It Works
2-4. Formatting Numbers
Problem
Solution
How It Works
2-5. Working with Arbitrary Precision Numbers
Problem
Solution
How It Works
2-6. Generating Random Numbers
Problem
Solution
How It Works
2-7. Getting the Current Date and Time
Problem
Solution
How It Works
2-8. Calculating Date/Time Differences
Problem
Solution
How It Works
2-9. Formatting Dates and Times
Problem
Solution
How It Works
2-10. Reading Dates and Times from a String
Problem
Solution
How It Works
Chapter 3: Iterators and Generators
3-1. Iterating Over the Contents of a List
Problem
Solution
How It Works
3-2. Extracting the Contents of an Iterator
Problem
Solution
How It Works
3-3. Filtering an Iterator
Problem
Solution
How It Works
3-4. Iterating Over the Contents of a File
Problem
Solution
How It Works
3-5. Iterating Over Data That Has no Iterator
Problem
Solution
How It Works
3-6. Creating Standard Classes of Iterators
Problem
Solution
How It Works
Chapter 4: Files and I/O
4-1. Copying Files
Problem
Solution
How It Works
4-2. Moving Files
Problem
Solution
How It Works
4-3. Reading and Writing Text Files
Problem
Solution
How It Works
4-4. Reading and Writing XML Files
Problem
Solution
How It Works
4-5. Creating a Directory
Problem
Solution
How It Works
4-6. Monitoring a Directory for Changes
Problem
Solution
How It Works
4-7. Iterating Over the Files in a Directory
Problem
Solution
How It Works
4-8. Saving Data Objects
Problem
Solution
How It Works
4-9. Compressing Files
Problem
Solution
How It Works
Chapter 5: Python Data Analysis with pandas
5-1. Working with 1D Data
Problem
Solution
How It Works
5-2. Working with 2D Data
Problem
Solution
How It Works
5-3. Working with 3D Data
Problem
Solution
How It Works
5-4. Importing Data from CSV Files
Problem
Solution
How It Works
5-5. Saving to a CSV File
Problem
Solution
How It Works
5-6. Importing from Spreadsheets
Problem
Solution
How It Works
5-7. Saving to a Spreadsheet
Problem
Solution
How It Works
5-8. Getting the Head and Tail
Problem
Solution
How It Works
5-9. Summarizing Data
Problem
Solution
How It Works
5-10. Sorting Data
Problem
Solution
How It Works
5-11. Applying Functions Row- or Column-Wise
Problem
Solution
How It Works
5-12. Applying Functions Element-Wise
Problem
Solution
How It Works
5-13. Iterating Over Data
Problem
Solution
How It Works
Chapter 6: Functions
6-1. Creating Basic Functions
Problem
Solution
How It Works
6-2. Using Named Parameters Rather Than Positional Parameters
Problem
Solution
How It Works
6-3. Using Default Values in Functions
Problem
Solution
How It Works
6-4. Implementing a Recursive Algorithm
Problem
Solution
How It Works
6-5. Using Lambda Functions to Create Temporary Anonymous Functions
Problem
Solution
How It Works
6-6. Generating Specialized Functions
Problem
Solution
How It Works
Chapter 7: Classes and Objects
7-1. Discovering the Type of an Object (Everything Is an Object)
Problem
Solution
How It Works
7-2. Creating Classes
Problem
Solution
How It Works
7-3. Adding Private Fields
Problem
Solution
How It Works
7-4. Subclassing
Problem
Solution
How It Works
7-5. Initializing Objects
Problem
Solution
How It Works
7-6. Comparing Objects
Problem
Solution
How It Works
7-7. Changing an Object After Creation
Problem
Solution
How It Works
7-8. Implementing Polymorphic Behavior
Problem
Solution
How It Works
Chapter 8: Metaprogramming
8-1. Using a Function Decorator to Wrap Existing Code
Problem
Solution
How It Works
8-2. Writing a Function Decorator to Wrap Existing Code
Problem
Solution
How It Works
8-3. Unwrapping a Decorated Function
Problem
Solution
How It Works
8-4. Using a Metaclass to Change the Construction of a Class
Problem
Solution
How It Works
8-5. Writing a Metaclass
Problem
Solution
How It Works
8-6. Using Signatures to Change the Parameters a Function Accepts
Problem
Solution
How It Works
Chapter 9: Networking and the Internet
9-1. Opening a Socket Connection
Problem
Solution
How It Works
9-2. Reading/Writing Over a Socket
Problem
Solution
How It Works
9-3. Reading an E-Mail with POP
Problem
Solution
How It Works
9-4. Reading an E-Mail with IMAP
Problem
Solution
How It Works
9-5. Sending an E-Mail
Problem
Solution
How It Works
9-6. Reading a Web Page
Problem
Solution
How It Works
9-7. Posting to a Web Page
Problem
Solution
How It Works
9-8. Acting as a Server
Problem
Solution
How It Works
Chapter 10: Modules and Packages
10-1. Importing Modules
Problem
Solution
How It Works
10-2. Installing Modules from Source
Problem
Solution
How It Works
10-3. Installing Modules from Pypi
Problem
Solution
How It Works
10-4. Upgrading a Module Using pip
Problem
Solution
How It Works
Chapter 11: Numerics and Numpy
11-1. Creating Arrays
Problem
Solution
How It Works
11-2. Copying an Array
Problem
Solution
How It Works
11-3. Accessing Array Data
Problem
Solution
How It Works
11-4. Manipulating a Matrix
Problem
Solution
How It Works
11-5. Calculating Fast Fourier Transforms
Problem
Solution
How It Works
11-6. Loading File Data into an Array
Problem
Solution
How It Works
11-7. Saving Arrays
Problem
Solution
How It Works
11-8. Generating Random Numbers
Problem
Solution
How It Works
11-9. Calculating Basic Statistics
Problem
Solution
How It Works
11-10. Computing Histograms
Problem
Solution
How It Works
Chapter 12: Concurrency
12-1. Creating a Thread
Problem
Solution
How It Works
12-2. Using Locks
Problem
Solution
How It Works
12-3. Setting a Barrier
Problem
Solution
How It Works
12-4. Creating a Process
Problem
Solution
How It Works
12-5. Communicating Between Processes
Problem
Solution
How It Works
12-6. Creating a Pool of Workers
Problem
Solution
How It Works
12-7. Creating a Subprocess
Problem
Solution
How It Works
12-8. Scheduling Events
Problem
Solution
How It Works
Chapter 13: Utilities
13-1. Creating a Virtual Environment
Problem
Solution
How It Works
13-2. Using the Ipython Shell
Problem
Solution
How It Works
13-3. Using the Jupyter Environment
Problem
Solution
How It Works
13-4. Using xonsh as a Replacement Shell
Problem
Solution
How It Works
Chapter 14: Testing and Debugging
14-1. Timing a Section of Code
Problem
Solution
How It Works
14-2. Profiling Code
Problem
Solution
How It Works
14-3. Tracing Subroutines
Problem
Solution
How It Works
14-4. Tracing Memory Allocations
Problem
Solution
How It Works
14-5. Performing Unit Tests
Problem
Solution
How It Works
14-6. Debugging Code
Problem
Solution
How It Works
Chapter 15: C and Other Extensions
15-1. Compiling Python Code
Problem
Solution
How It Works
15-2. Using Static Types
Problem
Solution
How It Works
15-3. Calling Python from C
Problem
Solution
How It Works
15-4. Calling C from Python
Problem
Solution
How It Works
Chapter 16: Arduino and RPi Recipes
16-1. Sending Data to an Arduino
Problem
Solution
How It Works
16-2. Reading Data from an Arduino
Problem
Solution
How It Works
16-3. Writing to the Raspberry Pi’s GPIO Bus
Problem
Solution
How It Works
16-4. Reading from the Raspberry Pi’s GPIO Bus
Problem
Solution
How It Works
Index