Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Series.cummax() is used to find Cumulative maximum of a series. In cumulative maximum, the length of returned series is same as input series and every element is equal to the greater one between current element and previous element.
Syntax: Series.cummax(axis=None, skipna=True)
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
In this example, a series is created from a Python list. The list also contains a Null value and the
skipna parameter is kept default, that is True.
0 3.0 1 4.0 2 NaN 3 7.0 4 7.0 5 7.0 dtype: float64
Explanation: Cummax is comparison of current value with previous value. The first element is always equal to first of caller series.
3 4 (4>3) NaN (Since NaN cannot be compared to integer values) 7 (7>4) 7 (7>2) 7 (7>0)
Example #2: Keeping
skipna = False
In this example, a series is created just like in the above example. But the skipna parameter is kept False. Hence NULL values won’t be ignored and it would be compared every time on it’s occurrence.
0 9.0 1 9.0 2 33.0 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN dtype: float64
Explanation: Just like in the above example, maximum of current and previous values were stored at every position until NaN occurred. Since NaN compared with anything returns NaN and skipna parameter is kept False, the cumulative maximum after its occurrence is NaN due to comparison of all the values with NaN.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Pandas series.cumprod() to find Cumulative product of a Series
- Python | Pandas Series.cumsum() to find cumulative sum of a Series
- Python | Pandas Series.cummin() to find cumulative minimum of a series
- Cumulative sum of a column in Pandas - Python
- Cumulative percentage of a column in Pandas - Python
- Add a Pandas series to another Pandas series
- Python program to find Cumulative sum of a list
- Python | CAP - Cumulative Accuracy Profile analysis
- Python - Cumulative Records Product
- Python - Cumulative product of dictionary value lists
- Python | Mathematical Median of Cumulative Records
- Python - Cumulative List Split
- Python | Pandas Series.str.replace() to replace text in a series
- Python | Pandas Series.astype() to convert Data type of series
- Python | Pandas Series.nonzero() to get Index of all non zero values in a series
- Python | Pandas Series.mad() to calculate Mean Absolute Deviation of a Series
- Normalized Discounted Cumulative Gain - Multilabel Ranking Metrics | ML
- How to create a Cumulative Histogram in Plotly?
- Convert a series of date strings to a time series in Pandas Dataframe
- Convert Series of lists to one Series in Pandas
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.