📜  Python| Pandas TimedeltaIndex.is_monotonic_decreasing(1)

📅  最后修改于: 2023-12-03 15:04:22.152000             🧑  作者: Mango

Python | Pandas TimedeltaIndex.is_monotonic_decreasing

Pandas TimedeltaIndex is a type of index that stores time durations as a list of timedelta objects. TimedeltaIndex.is_monotonic_decreasing is a property of TimedeltaIndex that returns True if the TimedeltaIndex is monotonic decreasing, which means that the elements in the TimedeltaIndex are in non-increasing order.

Syntax:
TimedeltaIndex.is_monotonic_decreasing
Return:

Return a bool indicating if the TimedeltaIndex is monotonic decreasing.

Description:

Consider the following TimedeltaIndex:

>>> import pandas as pd
>>> td = [pd.Timedelta(days=i) for i in range(5)]
>>> tdi = pd.TimedeltaIndex(td)
>>> tdi
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'], dtype='timedelta64[ns]', freq=None)

We can see that the TimedeltaIndex is in increasing order.

Now, suppose we reverse the order of the elements in the TimedeltaIndex:

>>> tdi_rev = tdi[::-1]
>>> tdi_rev
TimedeltaIndex(['4 days', '3 days', '2 days', '1 days', '0 days'], dtype='timedelta64[ns]', freq=None)

We can see that the TimedeltaIndex is now in non-increasing order.

We can use the TimedeltaIndex.is_monotonic_decreasing property to check if the TimedeltaIndex is monotonic decreasing:

>>> tdi.is_monotonic_decreasing
False

>>> tdi_rev.is_monotonic_decreasing
True

Therefore, TimedeltaIndex.is_monotonic_decreasing returns True for a TimedeltaIndex that is in non-increasing order.

Example:
>>> import pandas as pd
>>> td = [pd.Timedelta(days=i) for i in range(5)]
>>> tdi = pd.TimedeltaIndex(td)
>>> tdi.is_monotonic_decreasing
False

>>> tdi_rev = tdi[::-1]
>>> tdi_rev.is_monotonic_decreasing
True
Conclusion:

Pandas TimedeltaIndex.is_monotonic_decreasing is a property that can be used to check if a TimedeltaIndex is in non-increasing order. It returns True if the TimedeltaIndex is monotonic decreasing.