Learn pandas

Labelled tables for loading, cleaning, analysing and reshaping data in Python

32 lessons · 7 hours · 4 levels · covers pandas 2.2+ (notes on 3.0)

pandas provides the DataFrame and Series: labelled, column-typed tables built on NumPy and Apache Arrow. It is the standard Python tool for reading data from files and databases, cleaning it, grouping, joining and reshaping it, and analysing time series. Learning it is the fastest route from raw data to answers in Python.

Before you start

pandas builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics10 lessons · 2 hours in total
2. PracticalUse it productively at work, with the usual idioms21 lessons · 4 hours in total
3. AdvancedThe less common features, performance and trade-offs28 lessons · 6 hours in total
4. ExpertInternals and the edge cases experts know32 lessons · 7 hours in total

The pandas tree

pandasSeriesSeriesDataFrameDataFrameIndex and alignmentIndex and alignmentReading CSV, Excel and ParquetReading CSV, Exceland ParquetSelecting with loc and ilocSelecting with locand ilocFiltering rowsFiltering rowsSorting and rankingSorting and rankingAdding and modifying columnsAdding andmodifying columnsExploring: describe and value_countsExploring: describeand value_countsMissing data basicsMissing data basicsgroupby and aggregationgroupby andaggregationmerge and joinmerge and joinConcatenating DataFramesConcatenatingDataFramesReshaping: pivot, melt, stackReshaping: pivot,melt, stackapply vs vectorized operationsapply vs vectorizedoperationsWorking with text (.str)Working with text(.str)Dates and times basicsDates and timesbasicsCategorical dataCategorical dataMethod chainingMethod chainingPlotting basicsPlotting basicsWriting data outWriting data outThe ndarrayThe ndarrayDictionariesDictionariesIndexing and slicingIndexing and slicingBoolean masksBoolean masksVectorized arithmeticVectorized arithmeticGROUP BY and HAVINGGROUP BY andHAVINGInner joinsInner joinsDefining functionsDefining functions
Essentials and Practical shown (21 of 32 lessons); the full list is below. Click a lesson to read it.

All 32 lessons, in order

Series and DataFrames

  1. Series · Essentials · 10 min

    A one-dimensional labelled array: values with a dtype plus an index of labels.

  2. DataFrame · Essentials · 12 min

    A table of labelled columns sharing one row index; the central object of pandas.

  3. Index and alignment · Essentials · 10 min

    pandas matches data by index label, not position, in arithmetic and assignment.

  4. Exploring: describe and value_counts · Essentials · 10 min

    Summarise a dataset quickly with info, describe, value_counts, nunique and basic statistics.

Reading and writing data

  1. Reading CSV, Excel and Parquet · Essentials · 15 min

    Load data with read_csv, read_excel and read_parquet, controlling columns, types, dates and missing markers.

  2. Writing data out · Practical · 10 min

    Save results with to_csv, to_parquet, to_excel and to_json, choosing formats and options deliberately.

  3. SQL interop: read_sql and to_sql · Advanced · 12 min

    Query databases into DataFrames with read_sql, write tables with to_sql, safely and efficiently.

Selecting and filtering

  1. Selecting with loc and iloc · Essentials · 12 min

    Select rows and columns by label with .loc and by integer position with .iloc.

  2. Filtering rows · Essentials · 10 min

    Keep rows matching conditions with boolean masks, isin, between, string tests and query.

  3. Sorting and ranking · Essentials · 8 min

    Order rows with sort_values and sort_index, get top-n rows with nlargest, and rank values.

Cleaning and transforming

  1. Adding and modifying columns · Essentials · 12 min

    Create, transform, rename, retype and drop columns with vectorized expressions, assign and np.where.

  2. Missing data basics · Essentials · 12 min

    Find, drop and fill missing values (NaN, None, NaT, pd.NA) with isna, dropna, fillna and ffill.

  3. apply vs vectorized operations · Practical · 12 min

    When apply, map and row-wise functions are appropriate, and how to replace them with vectorized code.

  4. Working with text (.str) · Practical · 12 min

    Clean, search, split and extract text columns with vectorized .str methods and regular expressions.

  5. Categorical data · Practical · 10 min

    Store repeated labels as integer codes with the category dtype, and use ordered categories.

  6. Method chaining · Practical · 10 min

    Write a pipeline as one readable chain using assign, query, pipe, loc with callables and rename.

Grouping and analysis

  1. groupby and aggregation · Practical · 18 min

    Split rows into groups, apply aggregations or transformations per group, and combine the results.

  2. Reshaping: pivot, melt, stack · Practical · 15 min

    Switch between long and wide layouts with pivot_table, pivot, melt, stack, unstack and crosstab.

  3. Plotting basics · Practical · 10 min

    Make quick line, bar, histogram and scatter charts straight from Series and DataFrames with .plot.

  4. MultiIndex (hierarchical indexing) · Advanced · 15 min

    Index rows or columns by several levels, select with tuples, xs and IndexSlice, and reshape between levels.

Combining data

  1. merge and join · Practical · 15 min

    Combine DataFrames on key columns or indexes with inner, left, right, outer and cross joins.

  2. Concatenating DataFrames · Practical · 10 min

    Stack DataFrames vertically or side by side with pd.concat, controlling index and column alignment.

Time series

  1. Dates and times basics · Practical · 15 min

    Parse dates with to_datetime, use the .dt accessor, date arithmetic, date ranges and DatetimeIndex slicing.

  2. Window functions: rolling, expanding, ewm · Advanced · 15 min

    Compute moving averages, running totals and exponentially weighted statistics, by count or by time.

  3. Time series resampling · Advanced · 15 min

    Change the frequency of time series with resample: downsample with aggregation, upsample with filling.

Dtypes and performance

  1. Performance: dtypes, memory, vectorization · Advanced · 18 min

    Make pandas fast and lean: measure memory, choose compact dtypes, read less, and avoid Python-level loops.

  2. Copy-on-write semantics · Advanced · 15 min

    How copy-on-write (default in pandas 3.0, opt-in in 2.x) defines when changes propagate, and why chained assignment stops working.

  3. Nullable and Arrow-backed dtypes · Advanced · 15 min

    Int64, boolean, string and ArrowDtype columns: proper missing values without float upcasting, and pd.NA logic.

Internals and scale

  1. Internals: BlockManager and Index engines · Expert · 20 min

    How DataFrames store columns in typed blocks, why fragmentation happens, and how indexes do fast lookups.

  2. Extension arrays and accessors · Expert · 20 min

    The ExtensionArray/ExtensionDtype interface behind Categorical, Int64 and Arrow types, and custom accessors.

  3. Scaling beyond memory · Expert · 20 min

    Handle data larger than RAM: chunking, column pruning, Parquet and Arrow, and when to switch to Polars, DuckDB or Dask.

  4. API edge cases and gotchas · Expert · 15 min

    The surprises experienced pandas users know: integer labels vs positions, alignment, NaN keys, dtype drift and more.