# Python | Pandas series.cummax () to find the cumulative maximum of a series

Pandas `Series.cummax() ` is used to find the cumulative maximum of a series. At the cumulative maximum, the length of the returned series is the same as the input series, and each element is equal to the greater one between the current element and the previous element.

Syntax: Series.cummax (axis = None, skipna = True)

Parameters:
axis: 0 or ’index’ for row wise operation and 1 or ’columns ’for column wise operation.
skipna: Skips NaN addition for elements after the very next one if True.

Return type: Series

Example # 1:
This example creates a series from a Python list. The list also contains a Null value, and the ` skipna ` parameter remains the default, which is True.

 ` # pandas module import ` ` import ` ` pandas as pd ` ` `  ` # numpy module import ` ` import ` ` numpy as np ` ` `  ` # list values ​​` ` values ​​` ` = ` ` [` ` 3 ` `, ` ` 4 ` `, np.nan, ` ` 7 ` `, ` ` 2 ` `, ` ` 0 ` `] ` ` `  ` # create a series from the list ` ` series ` ` = ` ` pd.Series (values) ` ` `  ` # calling method ` ` cummax ` ` = ` ` series.cummax () `   ` # display ` ` cummax `

Output:

` 0 3.0 1 4.0 2 NaN 3 7.0 4 7.0 5 7.0 dtype: float64 `

Explanation: Cummax — it is a comparison of the current value with the previous value. The first element is always the first of the caller.

` 3 4 (4" 3) NaN (Since NaN cannot be compared to integer values) 7 (7" 4) 7 (7" 2) 7 (7" 0) `

Example # 2: saving ` skipna = False `

This example creates a series in the same way as above example. But the skipna parameter remains False. Therefore, NULL values ​​will not be ignored and they will be compared each time they are found.

 ` # pandas module import ` ` import ` ` pandas as pd `   ` # numpy module import ` ` import ` ` numpy as np `   ` # compiling a list of values ​​` ` values ​​` ` = ` ` [` ` 9 ` `, ` ` 4 ` `, ` ` 33 ` `, np.nan, ` ` 0 ` `, ` ` 1 ` `, ` ` 76 ` `, ` ` 5 ` `] `   ` # create a series from the list ` ` series ` ` = ` ` pd.Series (values) `   ` # calling method ` ` cummax ` ` = ` ` series.cummax (skipna ` ` = ` ` False ` `) `   ` # display ` ` cummax `

Exit:

` 0 9.0 1 9.0 2 33.0 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN dtype: float64 `

Explanation: How and in the above example, the maximum current and previous values ​​were kept at each position until NaN appeared. Since NaN is NaN compared to anything, and skipna remains False, the cumulative maximum after it appears is NaN due to the comparison of all values ​​to NaN.

## Shop Learn programming in R: courses

\$FREE Best Python online courses for 2022

\$FREE Best laptop for Fortnite

\$399+ Best laptop for Excel

\$ Best laptop for Solidworks

\$399+ Best laptop for Roblox

\$399+ Best computer for crypto mining

\$499+ Best laptop for Sims 4

\$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries