📜  Python| Pandas TimedeltaIndex.is_monotonic

📅  最后修改于: 2022-05-13 01:54:40.045000             🧑  作者: Mango

Python| Pandas TimedeltaIndex.is_monotonic

Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas TimedeltaIndex.is_monotonic属性检查给定的 TimedeltaIndex 对象是否是单调的。如果对象是单调的,则函数返回True否则返回False 。单调意味着对象中的值以永远不会减少或永远不会增加的方式变化。

示例 #1:使用TimedeltaIndex.is_monotonic属性检查 TimedeltaIndex 对象是否是单调的。

# importing pandas as pd
import pandas as pd
  
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(start ='1 days 02:00:00', periods = 5, freq ='T')
  
# Print the TimedeltaIndex
print(tidx)

输出 :

现在我们将检查 TimedeltaIndex 对象是否是单调的。

# check if tidx is monotonic or not
tidx.is_monotonic

输出 :

正如我们在输出中看到的, TimedeltaIndex.is_monotonic属性返回了True ,表明 tidx 是单调的。示例 #2:使用TimedeltaIndex.is_monotonic属性检查 TimedeltaIndex 对象是否是单调的。

# importing pandas as pd
import pandas as pd
  
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =['-1 days 2 min 3us', '1 days 06:05:01.000030',
                                                 '-1 days + 23:59:59.999999'])
  
# Print the TimedeltaIndex
print(tidx)

输出 :

现在我们将检查 TimedeltaIndex 对象是否是单调的。

# check if tidx is monotonic or not
tidx.is_monotonic

输出 :

正如我们在输出中看到的, TimedeltaIndex.is_monotonic属性返回了False ,表明 tidx 不是单调的。