当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python pyspark Series.is_monotonic_decreasing用法及代码示例


本文简要介绍 pyspark.pandas.Series.is_monotonic_decreasing 的用法。

用法:

property Series.is_monotonic_decreasing

如果对象中的值单调递减,则返回布尔值。

注意

is_monotonic_decreasing 的当前实现需要多次洗牌和聚合来检查本地和全局的顺序,这可能会很昂贵。在多索引的情况下,所有数据都传输到单个节点,目前很容易导致内存不足错误。

注意

如果您使用 pandas-on-Spark < 1.7.0 和 PySpark 3.1.1,请禁用 Spark 配置 spark.sql.optimizer.nestedSchemaPruning.enabled 进行多索引。

返回

is_monotonicbool

例子

>>> ser = ps.Series(['4/1/2018', '3/1/2018', '1/1/2018'])
>>> ser.is_monotonic_decreasing
True
>>> df = ps.DataFrame({'dates': [None, '3/1/2018', '2/1/2018', '1/1/2018']})
>>> df.dates.is_monotonic_decreasing
False
>>> df.index.is_monotonic_decreasing
False
>>> ser = ps.Series([1])
>>> ser.is_monotonic_decreasing
True
>>> ser = ps.Series([])
>>> ser.is_monotonic_decreasing
True
>>> ser.rename("a").to_frame().set_index("a").index.is_monotonic_decreasing
True
>>> ser = ps.Series([5, 4, 3, 2, 1], index=[1, 2, 3, 4, 5])
>>> ser.is_monotonic_decreasing
True
>>> ser.index.is_monotonic_decreasing
False

支持MultiIndex

>>> midx = ps.MultiIndex.from_tuples(
... [('x', 'a'), ('x', 'b'), ('y', 'c'), ('y', 'd'), ('z', 'e')])
>>> midx  
MultiIndex([('x', 'a'),
            ('x', 'b'),
            ('y', 'c'),
            ('y', 'd'),
            ('z', 'e')],
           )
>>> midx.is_monotonic_decreasing
False
>>> midx = ps.MultiIndex.from_tuples(
... [('z', 'e'), ('z', 'd'), ('y', 'c'), ('y', 'b'), ('x', 'a')])
>>> midx  
MultiIndex([('z', 'a'),
            ('z', 'b'),
            ('y', 'c'),
            ('y', 'd'),
            ('x', 'e')],
           )
>>> midx.is_monotonic_decreasing
True

相关用法


注:本文由纯净天空筛选整理自spark.apache.org大神的英文原创作品 pyspark.pandas.Series.is_monotonic_decreasing。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。