pyspark.pandas.DataFrame.swapaxes¶
-
DataFrame.
swapaxes
(i: Union[int, str], j: Union[int, str], copy: bool = True) → pyspark.pandas.frame.DataFrame[source]¶ Interchange axes and swap values axes appropriately.
Note
This method is based on an expensive operation due to the nature of big data. Internally it needs to generate each row for each value, and then group twice - it is a huge operation. To prevent misuse, this method has the ‘compute.max_rows’ default limit of input length and raises a ValueError.
>>> from pyspark.pandas.config import option_context >>> with option_context('compute.max_rows', 1000): ... ps.DataFrame({'a': range(1001)}).swapaxes(i=0, j=1) Traceback (most recent call last): ... ValueError: Current DataFrame's length exceeds the given limit of 1000 rows. Please set 'compute.max_rows' by using 'pyspark.pandas.config.set_option' to retrieve more than 1000 rows. Note that, before changing the 'compute.max_rows', this operation is considerably expensive.
- Parameters
- i: {0 or ‘index’, 1 or ‘columns’}. The axis to swap.
- j: {0 or ‘index’, 1 or ‘columns’}. The axis to swap.
- copybool, default True.
- Returns
- DataFrame
Examples
>>> psdf = ps.DataFrame( ... [[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=['x', 'y', 'z'], columns=['a', 'b', 'c'] ... ) >>> psdf a b c x 1 2 3 y 4 5 6 z 7 8 9 >>> psdf.swapaxes(i=1, j=0) x y z a 1 4 7 b 2 5 8 c 3 6 9 >>> psdf.swapaxes(i=1, j=1) a b c x 1 2 3 y 4 5 6 z 7 8 9