Python Pandas – 如果索引是单调递增的(仅相等或递增的值),则返回

Python Pandas – 如果索引是单调递增的(仅相等或递增的值),则返回

要返回索引是否是单调递增的(仅相等或递增的值),请使用 index.is_monotonic_increasing 属性。

首先,导入所需的库 –

import pandas as pd
Python

创建索引 –

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

显示该索引 –

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

检查索引是否单调递增 –

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

示例

以下是代码 –

import pandas as pd

# 创建索引
index = pd.Index([10, 20, 20, 30, 40])

# 显示索引
print("Pandas Index...\n",index)

# 返回代表索引中数据的数组
print("\nArray...\n",index.values)

# 检查索引是否单调递增
print("\nIs the Pandas index monotonic increasing?\n",index.is_monotonic_increasing)
Python

输出

这将产生以下代码 –

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

Array...
[10 20 20 30 40]

Is the Pandas index monotonic increasing?
True
Python

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册