Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Module

df.cummax

Returns the cumulative maximum along a DataFrame or Series axis. By default, it scans each column downward while preserving the input shape.

How it works

For each column by default, cummax scans rows from top to bottom and replaces each value with the largest value encountered so far. Set axis=1 to scan across columns within each row; skipna controls missing-value handling, while numeric_only restricts the operation to numeric and boolean columns.

Syntax

DataFrame.cummax(axis=0, skipna=True, numeric_only=False, **args, **kwargs)

Parameters

NameTypeDescription
axis{0 or 'index', 1 or 'columns'}, default 0Axis over which to calculate the cumulative maximum: 0 or 'index' scans rows, while 1 or 'columns' scans columns. Default: 0.
skipnabool, default TrueWhether to exclude NA/null values. Default: True.
numeric_onlybool, default FalseWhether to include only float, integer, and boolean columns. Default: False.
argstupleAdditional arguments accepted for compatibility.
kwargsdictAdditional keyword arguments accepted for compatibility.

Returns

DataFrame or Series of the same size containing cumulative maximum values.

Key points

  • The method computes a running maximum along the selected DataFrame axis.
  • For a DataFrame, the output preserves the input dimensions and corresponding cumulative positions.
  • axis=0, None, or 'index' selects the default top-to-bottom traversal.
  • axis=1 scans horizontally, producing each row's running maximum across its columns.
  • The default operation independently tracks a running maximum for every column.
  • skipna=True ignores missing entries when determining cumulative maxima.

Common mistakes

  • An all-missing row or column remains missing even when skipna is enabled.
  • With numeric_only=True, non-numeric columns are excluded from the calculation.

Example: Track running highs

import pandas as pd

prices = pd.DataFrame({"open": [10, 12, 11], "close": [11, 13, 12]})
prices["record_close"] = prices["close"].cummax()
print(prices)

Tracks the highest closing price reached at each row.

When to use it

Track record highs over time

Time-ordered measurements

Compute left-to-right running maxima with axis=1

Wide tabular records

Limit processing to numeric and boolean columns

Mixed-type DataFrames

Interview questions

QWhat does DataFrame.cummax return, and what is its default direction?

DataFrame.cummax returns a DataFrame of the same size containing cumulative maxima. Its default axis=0 scans down each column, so every position reflects the greatest value up to that row.

Follow-up: How would you compute running maxima across each row? Use axis=1, which iterates over columns and computes the maximum seen from left to right.

QHow does skipna affect cumulative maxima?

skipna defaults to True, so missing values are excluded when calculating later cumulative maxima. However, an entirely missing row or column produces missing output.

Follow-up: What changes with skipna=False? Missing values participate in propagation, so a missing value can cause subsequent cumulative results along that axis to remain missing.

QWhat does numeric_only control?

numeric_only defaults to False and determines whether all supported columns or only numeric and boolean columns are included. Setting it to True excludes non-numeric columns from the operation.

Follow-up: When is numeric_only=True useful? It is useful when a DataFrame mixes measurements with labels and the cumulative operation should apply only to measurement columns.

  • DataFrame.cummin
  • DataFrame.cumprod
  • DataFrame.cumsum
  • Series.cummax

Source: pandas.DataFrame.cummax — pandas 3.0.6 documentation. Checked 2026-10-15.