Preface
Acknowledgments
Contents
About the Authors
1 Basic Python
1.1 Introduction
1.2 Variables
1.3 Data Types
1.4 Operators
1.4.1 Arithmetic Operators
1.4.2 Relational Operators
1.4.3 Logical Operators
1.4.4 Bitwise Operators
1.4.5 Assignment Operators
1.4.6 Identity Operators
1.4.7 Membership Operators
1.4.8 Operators Precedence and Associativity
1.5 Type Conversions
1.6 Statements
1.6.1 Assignment Statement
1.6.2 Input Statement
1.6.3 Output Statement
1.6.4 Conditional Statement
1.6.5 Loop Statements
1.7 Random Numbers
2 Functions
2.1 Introduction
2.2 Properties of Functions
2.3 Parameters' Mapping
2.4 Parameter Passing Mechanisms
2.5 Recursive Functions
2.6 Lambda Functions
3 Strings
3.1 Create String Objects
3.2 Accessing String Objects
3.3 Operations on Strings
3.4 Methods on Strings
3.5 Iterating Through String Objects
3.6 Type Conversions
4 Built-in Data Structures: Lists
4.1 Create List Objects
4.2 Indexing and Slicing
4.3 Nested Lists
4.4 Methods on List Objects
4.5 Functions on List Objects
4.6 List Objects in for Loops
4.7 List Comprehensions
5 Built-in Data Structure: Tuple
5.1 Create Tuple Objects
5.2 Indexing and Slicing
5.3 Nested Tuples
5.4 Operations on Tuples
5.5 Functions on Tuples
5.6 Methods on Tuple Objects
5.7 Type Conversions
5.8 Iterating Tuple Objects
5.9 Unpacking
5.10 Enumerations
5.11 Zipping
6 Built-in Data Structure: Sets
6.1 Create Set Objects
6.2 Properties of Sets
6.3 Membership Testing
6.4 Functions on Set Objects
6.5 Methods on Set Objects
6.6 Operations on Sets
6.7 Type Conversions
6.8 Set Comprehensions
6.9 Frozen Sets
7 Built-in Data Structure: Dictionary
7.1 Create Dictionary Objects
7.2 Properties of Dictionary Objects
7.3 Accessing the Elements
7.4 Operations on Dictionary Objects
7.5 Iterating Dictionary Objects
7.6 Dictionary Comprehension
7.7 Type Conversions
8 Files
8.1 Introduction
8.2 File Handling
8.2.1 Opening the File
8.2.2 Closing the File
8.2.3 Writing Data into Files
8.2.4 Get File Pointer Position
8.2.5 Reading Data from Files
8.2.6 Changing the File Pointer Position
8.2.7 Read and Write to Files
8.3 Working with Files and Directories
8.4 Case Study: File Handling
9 Data Manipulations with Pandas
9.1 Introduction
9.2 Dataframes
9.2.1 Create Dataframes
9.2.2 Attributes of a Dataframe
9.2.3 Add Columns
9.2.4 Accessing Data
9.2.5 Adding Rows
9.2.6 Deleting Columns
9.2.7 Renaming Column Names and Row Labels
9.2.8 Methods on Dataframes
9.2.9 Functions on Columns
9.2.10 Operators on Dataframes
9.3 Dataframes and Files
9.4 User-Defined Modules
9.5 Case Study: Data Manipulation and Analysis
10 SQLite3
10.1 SQL Commands
10.1.1 Data Definition Language (DDL)
10.1.2 Data Manipulation Language (DML)
10.1.3 Data Query Language (DQL)
10.1.4 Examples
10.2 Case Study: Database Creation and Operations
11 Regular Expressions
11.1 Meta Characters and Special Sequences
11.2 Functions on Regular Expressions
11.3 Case Study: Regular Expressions
12 Data Visualizations
12.1 Matplotlib
12.2 Seaborn
12.3 General Functions in Plotting
12.4 Basic Graphs and Plots
12.5 Subplots
12.6 Case Study: Data Visualizations
13 Python for Machine Learning
13.1 Data Loading
13.2 Data Preparation and Preprocessing
13.2.1 Data Cleaning
13.2.2 Data Transformations
13.2.3 Splitting the Dataset
13.3 Case Study: Preprocessing on the Titanic Dataset
13.4 Supervised Learning
13.4.1 Regression
13.4.2 Classification
13.5 Model Selection
13.5.1 Hyperparameter Tuning
13.5.2 Case Study
13.6 Ensemble Methods
13.6.1 Basic Ensembling Techniques
13.6.2 Advanced Ensembling Techniques
13.6.3 Case Study
13.7 Unsupervised Learning
13.7.1 Unsupervised Learning Techniques
13.7.2 Clustering Methods
13.7.3 Case Study
14 Python for Deep Learning
14.1 Introduction
14.2 Data Loading
14.2.1 In-built Datasets
14.2.2 Loading csv Dataset
14.3 Image Data Loading and Preparation
14.4 Text Data Loading and Preparation
14.5 Model Building
14.5.1 Activation Functions
14.5.2 Neural Network Layers
14.5.3 Methods on the Model
14.5.4 Model Compilation
14.5.5 Model Training
14.5.6 Model Evaluation
14.5.7 Model Prediction
14.6 Autoencoder
14.7 Case Studies
14.7.1 Regression Model on Boston Housing Dataset
14.7.2 Deep Neural Network for Breast Cancer Classification
14.7.3 Image Classification Model
14.7.4 Text Data Classification
15 Python for Multi-tasking
15.1 Introduction
15.2 Multi-threading
15.2.1 Threads Synchronization
15.3 Multi-processing
15.3.1 Interprocess Communication
15.3.2 Process Pool
Appendix A Solutions to Review Questions
Appendix B Python Installation
Index
The book is designed to serve as a textbook for courses offered to undergraduate and graduate students enrolled in data science. This book aims to help the readers understand the basic and advanced concepts for developing simple programs and the fundamentals required for building machine learning models. The book covers basic concepts like data types, operators, and statements that enable the reader to solve simple problems. As functions are the core of any programming, a detailed illustration of defining & invoking functions and recursive functions is covered. Built-in data structures of Python, such as strings, lists, tuples, sets, and dictionary structures, are discussed in detail with examples and exercise problems. Files are an integrated part of programming when dealing with large data. File handling operations are illustrated with examples and a case study at the end of the chapter. Widely used Python packages for data science, such as Pandas, Data Visualization libraries, and regular expressions, are discussed with examples and case studies at the end of the chapters. The book also contains a chapter on SQLite3, a small relational database management system of Python, to understand how to create and manage databases. As AI applications are becoming popular for developing intelligent solutions to various problems, the book includes chapters on Machine Learning and Deep Learning. They cover the basic concepts, example applications, and case studies using popular frameworks such as SKLearn and Keras on public datasets.