Python Pandas - 返回索引是否为单调递减(仅相等或递减)值
如要返回索引是否为单调递减(仅相等或递减)的值,请使用 index.is_monotonic_decreasing 属性。
首先,导入所需的库 −
import pandas as pd
创建索引 −
index = pd.Index([50, 40, 30, 30, 30])
显示索引 −
print("Pandas Index...\n",index)检查索引是否单调递减 −
print("\nIs the Pandas index monotonic decreasing?\n",index.is_monotonic_decreasing)
示例
代码如下 −
import pandas as pd
# Creating the index
index = pd.Index([50, 40, 30, 30, 30])
# 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 decreasing
print("\nIs the Pandas index monotonic decreasing?\n",index.is_monotonic_decreasing)输出
这将生成以下代码 −
Pandas Index... Int64Index([50, 40, 30, 30, 30], dtype='int64') Array... [50 40 30 30 30] Is the Pandas index monotonic decreasing? True
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP