Python for AI and Data Analysis
Not a programmer by trade, but still want to use Python and AI in your day-to-day work? No problem! Learn how to use Python to analyze data, automate tasks, and work with models without getting bogged down by unnecessary busy work. You’ll learn about key tools like Visual Studio Code and Jupyter Notebooks and then jump straight into data analysis and visualization with NumPy, pandas, and Matplotlib. Hands-on examples will have you learning to clean, filter, and transform data, perform calculations, and create charts and interactive plots—right out of the gate!
- A practical guide to Python for AI and data projects
- Learn to analyze and visualize data with NumPy, pandas, and Matplotlib
- Use AI and machine learning for predictive modeling, text analysis, and image recognition
You'll learn about:
- Data Analysis and Visualization:
Get hands on with the Python data stack. Use NumPy and pandas to load, clean, filter, and transform data from CSV, Excel, JSON, and other formats. Then turn your results into compelling charts and interactive plots with Matplotlib.
- Machine Learning and AI:
Apply the tools professionals use! Work through classical machine learning methods—linear regression, decision trees, clustering, and more—before moving into natural language processing, sentiment analysis, image classification, and deep learning.
- Automation and Real-World Applications:
Take Python beyond analysis. Build lightweight web tools with Flask and Streamlit, scrape web pages, query databases, and automate recurring tasks—from PDF processing and document generation to scheduled data retrieval and email notifications.
Key Highlights:
- Python fundamentals
- Data analysis
- Data visualization
- Machine learning
- Natural language processing
- Text and sentiment analysis
- Image recognition and classification
- APIs and web scraping
- Database access
- Task automation
View Full Table of Contents
- 1 Introduction
- 1.1 Future Skill: Programming
- 1.2 Python
- 1.3 Artificial Intelligence
- 1.4 Machine Learning
- 1.5 Programming with the Help of AI
- 1.6 Prompt Engineering
- 2 Getting Started with Python
- 2.1 Installing Python on Windows
- 2.2 Installing Python on macOS and Linux
- 2.3 Using Python in Interactive Mode
- 2.4 Python Scripts
- 2.5 Visual Studio Code and Integrated Development Environments
- 2.6 Jupyter Notebooks
- 2.6.1 Creating Jupyter Notebooks in Visual Studio Code
- 2.6.2 Markdown Cells
- 2.6.3 Code Cells
- 3 Basics of the Python Language
- 3.1 Variables and Data Types
- 3.2 Comments
- 3.3 Functions
- 3.4 Conditionals with "if," "elif," and "else"
- 3.5 Comparison Operators
- 3.6 Numbers
- 3.7 The "while" Loop
- 3.8 The “for” Loop
- 3.9 More on "print"
- 3.10 Lists, Sets, Tuples, and Dictionaries
- 3.11 "for" Loop for Lists and More
- 3.12 Sample Program: Counting Words
- 3.13 Writing Your Own Functions
- 3.14 Pythonic Code
- 3.14.1 Create a New List from a List
- 3.14.2 Filtering Elements from a List
- 3.14.3 Concatenating Strings Without "+"
- 3.14.4 Searching for a Value in a List
- 3.14.5 Tuple Decomposition
- 3.14.6 Loop Counters
- 3.14.7 Iterating over the Key-Value Pairs in a Dictionary
- 3.14.8 Swapping Variable Values
- 3.14.9 Assigning a Boolean Directly
- 3.14.10 Case Differentiation
- 3.14.11 Retrieving a Default Value from a Dictionary
- 3.14.12 Walrus Operator
- 3.15 Importing Modules and Installing Packages with "pip"
- 3.16 Virtual Environments
- 4 Working with Files
- 4.1 Reading and Writing Text Files
- 4.2 Comma-Separated Values Files
- 4.3 Managing Files
- 4.3.1 Creating a File
- 4.3.2 Checking for File Existence and Deleting Files
- 4.3.3 Moving, Renaming, and Copying Files
- 4.3.4 Listing Files in a Directory
- 4.4 Example: Text Analysis
- 4.5 Excel Files
- 4.6 Image Files
- 4.7 JSON Files
- 4.8 XML Files
- 4.9 Configuration Files
- 5 Data Analysis
- 5.1 NumPy
- 5.2 Pandas
- 5.3 Loading Data from Files into Pandas DataFrames
- 5.4 Data Cleaning with Pandas
- 5.4.1 Filtering Data
- 5.4.2 Identifying and Handling Missing Values
- 5.4.3 Removing Duplicates
- 5.4.4 Identifying and Correcting Errors and Outliers
- 5.4.5 Transforming Data into the Desired Format
- 5.4.6 (De)coding Categories
- 5.4.7 Normalizing: Making Values Comparable
- 5.5 Calculations and Analyses with Pandas
- 5.5.1 Row-by-Row Calculations
- 5.5.2 Differences from the Previous Value
- 5.5.3 Aggregating Values
- 5.5.4 Cumulative Sums
- 5.5.5 Grouping Data
- 5.5.6 Sorting and Ranking Data
- 5.6 Merging Data from Multiple Sources
- 6 Visualizations with Matplotlib
- 6.1 Creating Plots
- 6.2 Design Options
- 6.3 Subplots: Multiple Plots in a Single Figure
- 6.4 Line Charts, Bar Charts, and More
- 6.5 Creating Charts from DataFrames
- 6.6 Interactive Charts
- 6.7 Zooming and Scrolling
- 7 Machine Learning and Artificial Intelligence
- 7.1 Predicting Numbers Using Linear Regression
- 7.2 Linear Regression with Multiple Factors
- 7.3 Classification Using Logistic Regression
- 7.4 Decision Trees and Random Forests
- 7.5 K-Nearest Neighbors
- 7.6 Support Vector Machines
- 7.7 Training Data, Test Data, and Model Evaluation
- 7.8 Clustering (Unsupervised Learning)
- 8 AI in Action: Text and Image Analysis
- 8.1 AI for Text and Language
- 8.2 Text Analysis and Word Clouds
- 8.3 Text Preprocessing
- 8.4 Sentiment Analysis
- 8.5 Recognizing Entities in Text: Named Entity Recognition
- 8.6 Transfer Learning
- 8.7 AI for Images
- 8.8 Image Preprocessing: Grayscale Conversion and More
- 8.9 Detecting Edges and Contours in Images
- 8.10 Classic Machine Learning Methods for Images
- 8.11 Image Classification with Deep Learning
- 9 Using APIs
- 9.1 API Requests with "requests"
- 9.2 API Access with Special SDKs
- 9.3 Visualizing and Analyzing API Data
- 9.4 ChatGPT API
- 10 Using Python on the Web
- 10.1 HTML
- 10.2 Flask: A Python Web Server
- 10.3 Interactive Web Tools with Streamlit
- 10.4 Reading Web Content with Beautiful Soup
- 10.5 Remotely Controlling the Browser with Selenium
- 10.6 Sending Emails and Messenger Messages
- 11 Databases
- 11.1 The SQL Language and the SQLite Console
- 11.2 Creating Tables with CREATE TABLE
- 11.3 Querying, Inserting, Updating, and Deleting with SELECT, INSERT, UPDATE, and DELETE
- 11.4 Accessing an SQLite Database with Python
- 11.5 Pandas DataFrame: Reading and Writing Data from Databases
- 12 Automating Routine Tasks
- 12.1 Retrieving Data via the API and Storing It in a Database
- 12.2 Creating Charts from the Database and Save as Image Files
- 12.3 Sending an Email When There’s Something New
- 12.4 Sending Screenshots of Web Pages via Messenger
- 12.5 Images: Reducing File Sizes, Finding Locations, and Cleaning Up
- 12.6 PDF: Splitting, Merging, and Consolidating Files
- 12.7 Recognizing Text on Business Card Images Using OCR and Saving to Your Phone’s Address Book
- 12.8 Creating Invoices, Mail Merges, and Other Documents
- 12.9 Running Python Scripts on a Schedule
- 12.10 Logging in Automations
- The Author
- Index