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