Python Pandas - 返回索引是单调递增值(仅等于或递增)
要返回索引是单调递增(仅等于或递增)的值,请使用 index.is_monotonic_increasing 属性。
首先,导入必需的库 −
import pandas as pd
创建索引 −
index = pd.Index([10, 20, 20, 30, 40])
显示索引 −
print("Pandas Index...\n",index)
检查索引是否单调递增 −
print("\nIs the Pandas index monotonic increasing?\n",index.is_monotonic_increasing)
示例
以下是代码 −
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)
输出
将生成以下代码 −
Pandas Index... Int64Index([10, 20, 20, 30, 40], dtype='int64') Array... [10 20 20 30 40] Is the Pandas index monotonic increasing? True
广告