Python for Data Science — Study Notes

Python for Data Science — Study Notes
Free study notes · Index
Python for Data Science — Study Notes

These 12 chapters take you from your first line of Python to deep learning, in about 93 minutes of reading. Each chapter below has a short overview and a list of what it covers, so you can start at the beginning or jump straight to the topic you need.

These are independent study notes, written in my own words and with my own examples, covering standard topics in Python, statistics and machine learning. They are not official course material and are not affiliated with or endorsed by any university, course provider or company.

How to use these notes

  • If you are new to the subject, read the chapters in order, because each one builds on the ones before it.
  • Every chapter opens with an In this chapter list, so you can jump straight to any section.
  • Every chapter ends with Exam points, which sum up the facts most worth remembering before a test.
  • The buttons at the bottom of each chapter take you to the previous chapter, the next chapter or back to this index.

Jump to a chapter

Chapter 1 of 12About 7 min read

Foundations of Data Science

This chapter explains what data science actually is and why it has grown so quickly. It walks through the five everyday operations of a data project and shows how data science, machine learning and artificial intelligence fit together.

In this chapter:

  • You will see how statistics, computer science and domain knowledge combine to form data science.
  • You will learn the five operations — collecting, storing, processing, describing and modelling data — and the skills each one needs.
  • You will compare statistical modelling with machine-learning modelling and understand when each is the better choice.
  • You will understand how AI, machine learning and data science differ, with real examples of each.
Read Chapter 1 →
Chapter 2 of 12About 6 min read

Python tools, Google Colab and datasets

Before analysing data you need the right tools, and this chapter sets them up. It introduces Python and its key libraries, shows how to work in Google Colab, and describes the four classic datasets used throughout these notes.

In this chapter:

  • You will learn why Python became the most popular language for data science and how its basic rules work.
  • You will compare IDLE, Jupyter, Colab and full code editors, and see when each one is useful.
  • You will practise three ways of loading a dataset into Colab, including straight from Kaggle and from Google Drive.
  • You will get to know the Crop, Pima Diabetes, California Housing and MNIST datasets and what each one predicts.
Read Chapter 2 →
Chapter 3 of 12About 14 min read

Statistics and probability

Statistics is the language of evidence, and every model you build relies on it. This chapter moves from describing data to drawing conclusions from samples, and finishes with the probability rules behind machine learning.

In this chapter:

  • You will learn to summarize data with the mean, median, mode, variance, standard deviation and box plots.
  • You will understand how samples are drawn and how inferential statistics generalizes from a sample to a population.
  • You will run hypothesis tests step by step, interpret p-values and choose between one- and two-tailed tests.
  • You will apply the basic probability rules, conditional probability and Bayes' theorem to worked examples.
Read Chapter 3 →
Chapter 4 of 12About 7 min read

Python fundamentals

This chapter covers the building blocks of every Python program. Once you are comfortable with data types, operators, decisions, loops and functions, every later chapter becomes much easier to follow.

In this chapter:

  • You will learn Python's core data types and how to read and convert user input safely.
  • You will master arithmetic, logical, bitwise, membership and identity operators, along with their precedence.
  • You will write decisions with if, elif and else, and control loops with break, continue and pass.
  • You will define your own functions and use positional, keyword, default, *args and **kwargs arguments.
Read Chapter 4 →
Chapter 5 of 12About 6 min read

Python data structures

Real programs store many values at once, and Python offers five main containers for doing that. This chapter explains how each one behaves, which operations it supports, and how to choose the right one for a job.

In this chapter:

  • You will learn to index and slice strings, lists and tuples, and use their most important methods.
  • You will understand the difference between mutable and immutable types, and avoid the classic list-copying trap.
  • You will use sets for fast membership tests and set algebra such as union, intersection and difference.
  • You will work with dictionaries for key-value data, including the counting pattern and comprehensions.
Read Chapter 5 →
Chapter 6 of 12About 6 min read

Advanced Python

Larger programs need structure, safety and a way to save their data. This chapter introduces object-oriented programming, shows how code is organized into modules and packages, and explains how to handle errors and files properly.

In this chapter:

  • You will learn the four pillars of OOP and write classes with constructors, methods and inheritance.
  • You will organize code into modules and packages, and understand the role of __init__.py.
  • You will handle exceptions cleanly with try, except, else and finally.
  • You will open, read, write and append to files, and use the with statement to close them safely.
Read Chapter 6 →
Chapter 7 of 12About 6 min read

NumPy and Pandas

NumPy and Pandas are the workhorses of data analysis in Python. This chapter shows how NumPy arrays make numerical work fast, and how Pandas DataFrames make it easy to load, filter, summarize and group real-world tables.

In this chapter:

  • You will create NumPy arrays, inspect their attributes and slice them in one, two and three dimensions.
  • You will understand copies versus views, generate random data and use broadcasting and the axis argument.
  • You will build Pandas Series and DataFrames and select data with loc, iloc and Boolean filters.
  • You will summarize and group data with describe(), groupby() and the split–apply–combine pattern.
Read Chapter 7 →
Chapter 8 of 12About 6 min read

Data storage, visualization and ML libraries

Analysis only becomes useful when it is combined, visualized and modelled. This chapter covers joining tables, choosing the right chart, and the main libraries you will use for machine learning and deep learning.

In this chapter:

  • You will save DataFrames to files and combine tables with inner, left, right and outer joins.
  • You will choose between histograms, KDE plots, box plots, violin plots, heatmaps and pair plots.
  • You will follow the standard Scikit-learn workflow from splitting data to evaluating a model.
  • You will compare TensorFlow, Keras and PyTorch and understand what each one is best at.
Read Chapter 8 →
Chapter 9 of 12About 7 min read

Data preprocessing

Most of the effort in a real project goes into preparing the data, and good preprocessing often matters more than the choice of algorithm. This chapter covers the cleaning and transformation steps that every model depends on.

In this chapter:

  • You will handle missing values by dropping or filling them, and know when each option makes sense.
  • You will fix class imbalance with over-sampling, under-sampling and SMOTE.
  • You will scale, encode and discretize features, and understand why distance-based models need scaling.
  • You will reduce features with selection and PCA, and prepare images and text for models.
Read Chapter 9 →
Chapter 10 of 12About 9 min read

Machine learning and supervised models

This chapter is your first real step into machine learning. It explains how supervised learning works, builds three classic models by hand, and shows how to measure whether a model is actually any good.

In this chapter:

  • You will understand the types of machine learning and the difference between regression and classification.
  • You will fit a linear regression line with the least-squares method using a worked example.
  • You will classify new points with KNN and build a decision tree using entropy and information gain.
  • You will evaluate models with MSE, RMSE, R², the confusion matrix, precision, recall, F1 and ROC-AUC.
Read Chapter 10 →
Chapter 11 of 12About 11 min read

Advanced ML and unsupervised learning

This chapter takes you deeper into how models learn and how to stop them from going wrong. It covers logistic regression and neural networks, the key ideas behind training, and the two main ways of finding groups in unlabelled data.

In this chapter:

  • You will see why logistic regression suits classification and how its decision boundary works.
  • You will learn how perceptrons and multilayer neural networks learn through backpropagation.
  • You will recognize underfitting and overfitting, and fix them with tuning, regularization and validation sets.
  • You will cluster data with K-means and hierarchical clustering, and judge the quality of the clusters.
Read Chapter 11 →
Chapter 12 of 12About 8 min read

Deep learning

Deep learning powers today's image recognition, speech assistants and language models. This final chapter explains what makes it different from traditional machine learning, and how CNNs and RNNs handle images and text.

In this chapter:

  • You will understand what deep learning is, why it took off, and how it compares with traditional machine learning.
  • You will learn how a CNN processes an image layer by layer, from convolution and pooling to classification.
  • You will compare the traditional Bag of Words approach to text with word embeddings and RNNs.
  • You will know the four types of RNN and the preprocessing steps needed for text classification.
Read Chapter 12 →

Credits and disclaimer

  • These notes are an original summary of widely taught concepts. All explanations and worked examples were written for this blog.
  • They are not affiliated with or endorsed by any university, MOOC platform or company. Product names (Python, Google Colab, Kaggle, NumPy, Pandas, Scikit-learn, TensorFlow, Keras, PyTorch and others) are trademarks of their respective owners.
  • Datasets mentioned belong to their creators: Pima Indians Diabetes (National Institute of Diabetes and Digestive and Kidney Diseases, via the UCI repository), California Housing Prices (1990 US Census; Pace and Barry, 1997), MNIST (LeCun, Cortes and Burges) and Crop Recommendation (Kaggle).
  • Notes are for learning only and may contain errors; check official documentation for the latest details.