Rearrange DataFrame into new partitions Uses hashing of `on` to map rows to output partitions. After this operation, rows with the same value of `on` will be in the same partition. Parameters ---------- on : str, list of str, or Series, Index, or Dat
(
self,
on: str | list | no_default = no_default, # type: ignore[valid-type]
ignore_index: bool = False,
npartitions: int | None = None,
shuffle_method: str | None = None,
on_index: bool = False,
force: bool = False,
**options,
)
| 876 | return self.partitions[n] |
| 877 | |
| 878 | def shuffle( |
| 879 | self, |
| 880 | on: str | list | no_default = no_default, # type: ignore[valid-type] |
| 881 | ignore_index: bool = False, |
| 882 | npartitions: int | None = None, |
| 883 | shuffle_method: str | None = None, |
| 884 | on_index: bool = False, |
| 885 | force: bool = False, |
| 886 | **options, |
| 887 | ): |
| 888 | """Rearrange DataFrame into new partitions |
| 889 | |
| 890 | Uses hashing of `on` to map rows to output partitions. After this |
| 891 | operation, rows with the same value of `on` will be in the same |
| 892 | partition. |
| 893 | |
| 894 | Parameters |
| 895 | ---------- |
| 896 | on : str, list of str, or Series, Index, or DataFrame |
| 897 | Column names to shuffle by. |
| 898 | ignore_index : optional |
| 899 | Whether to ignore the index. Default is ``False``. |
| 900 | npartitions : optional |
| 901 | Number of output partitions. The partition count will |
| 902 | be preserved by default. |
| 903 | shuffle_method : optional |
| 904 | Desired shuffle method. Default chosen at optimization time. |
| 905 | on_index : bool, default False |
| 906 | Whether to shuffle on the index. Mutually exclusive with 'on'. |
| 907 | Set this to ``True`` if 'on' is not provided. |
| 908 | force : bool, default False |
| 909 | This forces the optimizer to keep the shuffle even if the final |
| 910 | expression could be further simplified. |
| 911 | **options : optional |
| 912 | Algorithm-specific options. |
| 913 | |
| 914 | Notes |
| 915 | ----- |
| 916 | This does not preserve a meaningful index/partitioning scheme. This |
| 917 | is not deterministic if done in parallel. |
| 918 | |
| 919 | Examples |
| 920 | -------- |
| 921 | >>> df = df.shuffle(df.columns[0]) # doctest: +SKIP |
| 922 | """ |
| 923 | if on is no_default and not on_index: # type: ignore[unreachable] |
| 924 | raise TypeError( |
| 925 | "Must shuffle on either columns or the index; currently shuffling on " |
| 926 | "neither. Pass column(s) to 'on' or set 'on_index' to True." |
| 927 | ) |
| 928 | elif on is not no_default and on_index: |
| 929 | raise TypeError( |
| 930 | "Cannot shuffle on both columns and the index. Do not pass column(s) " |
| 931 | "to 'on' or set 'on_index' to False." |
| 932 | ) |
| 933 | |
| 934 | # Preserve partition count by default |
| 935 | npartitions = npartitions or self.npartitions |