MCPcopy Create free account
hub / github.com/dask/dask / set_index

Method set_index

dask/dataframe/dask_expr/_collection.py:3342–3532  ·  view source on GitHub ↗

Set the DataFrame index (row labels) using an existing column. If ``sort=False``, this function operates exactly like ``pandas.set_index`` and sets the index on the DataFrame. If ``sort=True`` (default), this function also sorts the DataFrame by the new index. This can have

(
        self,
        other,
        drop=True,
        sorted=False,
        npartitions: int | None = None,
        divisions=None,
        sort: bool = True,
        shuffle_method=None,
        upsample: float = 1.0,
        partition_size: float = 128e6,
        append: bool = False,
        **options,
    )

Source from the content-addressed store, hash-verified

3340 return new_collection(Eval(self, _expr=expr, expr_kwargs=kwargs))
3341
3342 def set_index(
3343 self,
3344 other,
3345 drop=True,
3346 sorted=False,
3347 npartitions: int | None = None,
3348 divisions=None,
3349 sort: bool = True,
3350 shuffle_method=None,
3351 upsample: float = 1.0,
3352 partition_size: float = 128e6,
3353 append: bool = False,
3354 **options,
3355 ):
3356 """Set the DataFrame index (row labels) using an existing column.
3357
3358 If ``sort=False``, this function operates exactly like ``pandas.set_index``
3359 and sets the index on the DataFrame. If ``sort=True`` (default),
3360 this function also sorts the DataFrame by the new index. This can have a
3361 significant impact on performance, because joins, groupbys, lookups, etc.
3362 are all much faster on that column. However, this performance increase
3363 comes with a cost, sorting a parallel dataset requires expensive shuffles.
3364 Often we ``set_index`` once directly after data ingest and filtering and
3365 then perform many cheap computations off of the sorted dataset.
3366
3367 With ``sort=True``, this function is much more expensive. Under normal
3368 operation this function does an initial pass over the index column to
3369 compute approximate quantiles to serve as future divisions. It then passes
3370 over the data a second time, splitting up each input partition into several
3371 pieces and sharing those pieces to all of the output partitions now in
3372 sorted order.
3373
3374 In some cases we can alleviate those costs, for example if your dataset is
3375 sorted already then we can avoid making many small pieces or if you know
3376 good values to split the new index column then we can avoid the initial
3377 pass over the data. For example if your new index is a datetime index and
3378 your data is already sorted by day then this entire operation can be done
3379 for free. You can control these options with the following parameters.
3380
3381 Parameters
3382 ----------
3383 other: string or Dask Series
3384 Column to use as index.
3385 drop: boolean, default True
3386 Delete column to be used as the new index.
3387 sorted: bool, optional
3388 If the index column is already sorted in increasing order.
3389 Defaults to False
3390 npartitions: int, None, or 'auto'
3391 The ideal number of output partitions. If None, use the same as
3392 the input. If 'auto' then decide by memory use.
3393 Only used when ``divisions`` is not given. If ``divisions`` is given,
3394 the number of output partitions will be ``len(divisions) - 1``.
3395 divisions: list, optional
3396 The "dividing lines" used to split the new index into partitions.
3397 For ``divisions=[0, 10, 50, 100]``, there would be three output partitions,
3398 where the new index contained [0, 10), [10, 50), and [50, 100), respectively.
3399 See https://docs.dask.org/en/latest/dataframe-design.html#partitions.

Calls 7

check_divisionsFunction · 0.90
new_collectionFunction · 0.90
SetIndexBlockwiseClass · 0.90
SetIndexClass · 0.90
get_specified_shuffleFunction · 0.90
anyFunction · 0.85