當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Pandas Index.is_monotonic用法及代碼示例

Pandas 索引是一個不變的ndarray,它實現了有序的,可切片的集合。它是存儲所有 Pandas 對象的軸標簽的基本對象。

Pandas Index.is_monotonic屬性是is_monotonic_increasing的別名。它返回True如果給定Index對象中的基礎數據單調增加,則返回False

用法: Index.is_monotonic

參數:沒有

返回:布爾值

範例1:采用Index.is_monotonic屬性以確定給定Index對象中的基礎數據是否單調增加。

# importing pandas as pd 
import pandas as pd 
  
# Creating the index 
idx = pd.Index([100, 200, 420, 888, 924]) 
  
# Print the index 
print(idx)

輸出:

Int64Index([100, 200, 420, 888, 924], dtype='int64')

現在我們將使用Index.is_monotonic屬性以確定給定Index對象中的基礎數據是否單調增加。

# check if the values in the Index 
# are monotonically increasing 
result = idx.is_monotonic 
  
# Print the result 
print(result)

輸出:

True

正如我們在輸出中看到的,Index.is_monotonic屬性已返回True指示給定Index對象的基礎數據正在單調增加。

範例2:采用Index.is_monotonic屬性以確定給定Index對象中的基礎數據是否單調增加。

# importing pandas as pd 
import pandas as pd 
  
# Creating the index 
idx = pd.Index(['2012-12-12', None, '2002-1-10', None]) 
  
# Print the index 
print(idx)

輸出:

Index(['2012-12-12', None, '2002-1-10', None], dtype='object')

現在我們將使用Index.is_monotonic屬性以確定給定Index對象中的基礎數據是否單調增加。

# check if the values in the Index 
# are monotonically increasing 
result = idx.is_monotonic 
  
# Print the result 
print(result)

輸出:

False

正如我們在輸出中看到的,Index.is_monotonic屬性已返回False指示給定Index對象的基礎數據不是單調增加的。



相關用法


注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Index.is_monotonic。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。