Python Pandas - 如果索引单调递减(仅相等或递减)值则返回
要返回索引是否单调递减(仅相等或递减)值,请使用index.is_monotonic_decresing属性。
首先,导入所需的库-
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 #创建索引 index = pd.Index([50, 40, 30, 30, 30]) #显示索引 print("Pandas Index...\n",index) #返回一个表示索引中数据的数组 print("\nArray...\n",index.values) #检查索引是否单调递减 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