pyspark.pandas.Index.is_monotonic_increasing ¶
-
property
Index.
is_monotonic_increasing
¶ -
返回布尔值,判断对象中的值是否单调递增。
注意
当前的 is_monotonic_increasing 实现需要多次洗牌和聚合,以在本地和全局检查顺序,这可能会非常耗费资源。在多索引的情况下,所有数据都会传输到单个节点,这很容易导致内存不足错误。
注意
如果您使用的是 pandas-on-Spark < 1.7.0 和 PySpark 3.1.1,请禁用 Spark 配置 spark.sql.optimizer.nestedSchemaPruning.enabled 以支持多索引。
- Returns
-
- is_monotonic bool
示例
>>> ser = ps.Series(['1/1/2018', '3/1/2018', '4/1/2018']) >>> ser.is_monotonic_increasing True
>>> df = ps.DataFrame({'dates': [None, '1/1/2018', '2/1/2018', '3/1/2018']}) >>> df.dates.is_monotonic_increasing False
>>> df.index.is_monotonic_increasing True
>>> ser = ps.Series([1]) >>> ser.is_monotonic_increasing True
>>> ser = ps.Series([]) >>> ser.is_monotonic_increasing True
>>> ser.rename("a").to_frame().set_index("a").index.is_monotonic_increasing True
>>> ser = ps.Series([5, 4, 3, 2, 1], index=[1, 2, 3, 4, 5]) >>> ser.is_monotonic_increasing False
>>> ser.index.is_monotonic_increasing True
支持多级索引
>>> 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_increasing True
>>> midx = ps.MultiIndex.from_tuples( ... [('z', 'a'), ('z', 'b'), ('y', 'c'), ('y', 'd'), ('x', 'e')]) >>> midx MultiIndex([('z', 'a'), ('z', 'b'), ('y', 'c'), ('y', 'd'), ('x', 'e')], ) >>> midx.is_monotonic_increasing False