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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP