Change language

Python | Pandas Series.cummin () to find the cumulative minimum of a series

| |

Pandas Series.cummin() is used to find the cumulative minimum of a series. In the cumulative minimum, the returned row is the same length as the input row, and each element is equal to the shorter one between the current element and the previous element.

Syntax: Series.cummin (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 Null, 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

cummin = series.cummin () 

 
# display
cummin

Output:

 0 3.0 1 3.0 2 NaN 3 3.0 4 2.0 5 0.0 dtype: float64 

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

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

Example # 2: saving skipna=False

In this example, a series is created in the same way as in the 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 ​​ = [ 12 , 4 , 33 , np.nan, 0 , 1 , 76 , 5

 
# create a series from the list

series = pd.Series (values) 

 
# calling method

cummin = series.cummin (skipna = False

 
# display
cummin 

Exit:

 0 12.0 1 4.0 2 4.0 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN dtype: float64 

Explanation: Ka to and in the previous example, the minimum of the current and previous values ​​was stored at each position until NaN appeared. Since NaN compared to anything returns NaN and skipna remains False, the cumulative minimum after it appears is NaN due to the comparison of all values ​​to NaN.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method