Instagram
youtube
Facebook
Twitter

Cumulative Maximum of a Column in Pandas

A Cumulative Maximum of a Column in Pandas?

Code Explanation:
● Library Import:
pandas is imported as pd.

● DataFrame Creation: A column 'Scores' is created in df.

● Cumulative Max: cummax() gives the max so far at each index.

● Store Result: Results are stored in the column 'Cumulative_Max'.

● Output Display: print(df) shows original and cumulative max columns.

 

Program:

import pandas as pd

df = pd.DataFrame({'Scores': [80, 85, 83, 90]})

df['Cumulative_Max'] = df['Scores'].cummax()

print(df)