Check if Pandas Index is Monotonic Increasing or Equal



To return if the index is monotonic increasing (only equal or increasing) values, use the index.is_monotonic_increasing property.

At first, import the required libraries −

import pandas as pd

Creating the index −

index = pd.Index([10, 20, 20, 30, 40])

Display the index −

print("Pandas Index...\n",index)

Check if the index monotonic increasing −

print("\nIs the Pandas index monotonic increasing?\n",index.is_monotonic_increasing)

Example

Following is the code −

Open Compiler
import pandas as pd # Creating the index index = pd.Index([10, 20, 20, 30, 40]) # Display the index print("Pandas Index...\n",index) # Return an array representing the data in the Index print("\nArray...\n",index.values) # Check if the index monotonic increasing print("\nIs the Pandas index monotonic increasing?\n",index.is_monotonic_increasing)

Output

This will produce the following code −

Pandas Index...
Int64Index([10, 20, 20, 30, 40], dtype='int64')

Array...
[10 20 20 30 40]

Is the Pandas index monotonic increasing?
True
Updated on: 2021-10-13T11:08:54+05:30

589 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements