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

Method set_index

dask/dataframe/dask_expr/_collection.py:3372–3562  ·  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

3370 return new_collection(Eval(self, _expr=expr, expr_kwargs=kwargs))
3371
3372 def set_index(
3373 self,
3374 other,
3375 drop=True,
3376 sorted=False,
3377 npartitions: int | None = None,
3378 divisions=None,
3379 sort: bool = True,
3380 shuffle_method=None,
3381 upsample: float = 1.0,
3382 partition_size: float = 128e6,
3383 append: bool = False,
3384 **options,
3385 ):
3386 """Set the DataFrame index (row labels) using an existing column.
3387
3388 If ``sort=False``, this function operates exactly like ``pandas.set_index``
3389 and sets the index on the DataFrame. If ``sort=True`` (default),
3390 this function also sorts the DataFrame by the new index. This can have a
3391 significant impact on performance, because joins, groupbys, lookups, etc.
3392 are all much faster on that column. However, this performance increase
3393 comes with a cost, sorting a parallel dataset requires expensive shuffles.
3394 Often we ``set_index`` once directly after data ingest and filtering and
3395 then perform many cheap computations off of the sorted dataset.
3396
3397 With ``sort=True``, this function is much more expensive. Under normal
3398 operation this function does an initial pass over the index column to
3399 compute approximate quantiles to serve as future divisions. It then passes
3400 over the data a second time, splitting up each input partition into several
3401 pieces and sharing those pieces to all of the output partitions now in
3402 sorted order.
3403
3404 In some cases we can alleviate those costs, for example if your dataset is
3405 sorted already then we can avoid making many small pieces or if you know
3406 good values to split the new index column then we can avoid the initial
3407 pass over the data. For example if your new index is a datetime index and
3408 your data is already sorted by day then this entire operation can be done
3409 for free. You can control these options with the following parameters.
3410
3411 Parameters
3412 ----------
3413 other: string or Dask Series
3414 Column to use as index.
3415 drop: boolean, default True
3416 Delete column to be used as the new index.
3417 sorted: bool, optional
3418 If the index column is already sorted in increasing order.
3419 Defaults to False
3420 npartitions: int, None, or 'auto'
3421 The ideal number of output partitions. If None, use the same as
3422 the input. If 'auto' then decide by memory use.
3423 Only used when ``divisions`` is not given. If ``divisions`` is given,
3424 the number of output partitions will be ``len(divisions) - 1``.
3425 divisions: list, optional
3426 The "dividing lines" used to split the new index into partitions.
3427 For ``divisions=[0, 10, 50, 100]``, there would be three output partitions,
3428 where the new index contained [0, 10), [10, 50), and [50, 100), respectively.
3429 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