def transpose(self) -> 'DataFrame':
    "\n        Transpose index and columns.\n\n        Reflect the DataFrame over its main diagonal by writing rows as columns\n        and vice-versa. The property :attr:`.T` is an accessor to the method\n        :meth:`transpose`.\n\n        .. note:: This method is based on an expensive operation due to the nature\n            of big data. Internally it needs to generate each row for each value, and\n            then group twice - it is a huge operation. To prevent misusage, this method\n            has the 'compute.max_rows' default limit of input length, and raises a ValueError.\n\n                >>> from pyspark.pandas.config import option_context\n                >>> with option_context('compute.max_rows', 1000):  # doctest: +NORMALIZE_WHITESPACE\n                ...     ps.DataFrame({'a': range(1001)}).transpose()\n                Traceback (most recent call last):\n                  ...\n                ValueError: Current DataFrame has more then the given limit 1000 rows.\n                Please set 'compute.max_rows' by using 'pyspark.pandas.config.set_option'\n                to retrieve to retrieve more than 1000 rows. Note that, before changing the\n                'compute.max_rows', this operation is considerably expensive.\n\n        Returns\n        -------\n        DataFrame\n            The transposed DataFrame.\n\n        Notes\n        -----\n        Transposing a DataFrame with mixed dtypes will result in a homogeneous\n        DataFrame with the coerced dtype. For instance, if int and float have\n        to be placed in same column, it becomes float. If type coercion is not\n        possible, it fails.\n\n        Also, note that the values in index should be unique because they become\n        unique column names.\n\n        In addition, if Spark 2.3 is used, the types should always be exactly same.\n\n        Examples\n        --------\n        **Square DataFrame with homogeneous dtype**\n\n        >>> d1 = {'col1': [1, 2], 'col2': [3, 4]}\n        >>> df1 = ps.DataFrame(data=d1, columns=['col1', 'col2'])\n        >>> df1\n           col1  col2\n        0     1     3\n        1     2     4\n\n        >>> df1_transposed = df1.T.sort_index()  # doctest: +SKIP\n        >>> df1_transposed  # doctest: +SKIP\n              0  1\n        col1  1  2\n        col2  3  4\n\n        When the dtype is homogeneous in the original DataFrame, we get a\n        transposed DataFrame with the same dtype:\n\n        >>> df1.dtypes\n        col1    int64\n        col2    int64\n        dtype: object\n        >>> df1_transposed.dtypes  # doctest: +SKIP\n        0    int64\n        1    int64\n        dtype: object\n\n        **Non-square DataFrame with mixed dtypes**\n\n        >>> d2 = {'score': [9.5, 8],\n        ...       'kids': [0, 0],\n        ...       'age': [12, 22]}\n        >>> df2 = ps.DataFrame(data=d2, columns=['score', 'kids', 'age'])\n        >>> df2\n           score  kids  age\n        0    9.5     0   12\n        1    8.0     0   22\n\n        >>> df2_transposed = df2.T.sort_index()  # doctest: +SKIP\n        >>> df2_transposed  # doctest: +SKIP\n                  0     1\n        age    12.0  22.0\n        kids    0.0   0.0\n        score   9.5   8.0\n\n        When the DataFrame has mixed dtypes, we get a transposed DataFrame with\n        the coerced dtype:\n\n        >>> df2.dtypes\n        score    float64\n        kids       int64\n        age        int64\n        dtype: object\n\n        >>> df2_transposed.dtypes  # doctest: +SKIP\n        0    float64\n        1    float64\n        dtype: object\n        "
    max_compute_count = get_option('compute.max_rows')
    if (max_compute_count is not None):
        pdf = self.head((max_compute_count + 1))._to_internal_pandas()
        if (len(pdf) > max_compute_count):
            raise ValueError("Current DataFrame has more then the given limit {0} rows. Please set 'compute.max_rows' by using 'pyspark.pandas.config.set_option' to retrieve to retrieve more than {0} rows. Note that, before changing the 'compute.max_rows', this operation is considerably expensive.".format(max_compute_count))
        return DataFrame(pdf.transpose())
    pairs = F.explode(F.array(*[F.struct(*[SF.lit(col).alias(SPARK_INDEX_NAME_FORMAT(i)) for (i, col) in enumerate(label)], *[self._internal.spark_column_for(label).alias('value')]) for label in self._internal.column_labels]))
    exploded_df = self._internal.spark_frame.withColumn('pairs', pairs).select([F.to_json(F.struct(F.array(*[scol for scol in self._internal.index_spark_columns]).alias('a'))).alias('index'), F.col('pairs.*')])
    internal_index_columns = [SPARK_INDEX_NAME_FORMAT(i) for i in range(self._internal.column_labels_level)]
    pivoted_df = exploded_df.groupBy(internal_index_columns).pivot('index')
    transposed_df = pivoted_df.agg(F.first(F.col('value')))
    new_data_columns = list(filter((lambda x: (x not in internal_index_columns)), transposed_df.columns))
    column_labels = [(None if ((len(label) == 1) and (label[0] is None)) else label) for label in (tuple(json.loads(col)['a']) for col in new_data_columns)]
    internal = InternalFrame(spark_frame=transposed_df, index_spark_columns=[scol_for(transposed_df, col) for col in internal_index_columns], index_names=self._internal.column_label_names, column_labels=column_labels, data_spark_columns=[scol_for(transposed_df, col) for col in new_data_columns], column_label_names=self._internal.index_names)
    return DataFrame(internal)
Transpose index and columns.

Reflect the DataFrame over its main diagonal by writing rows as columns
and vice-versa. The property :attr:`.T` is an accessor to the method
:meth:`transpose`.

.. 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 misusage, 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):  # doctest: +NORMALIZE_WHITESPACE
        ...     ps.DataFrame({'a': range(1001)}).transpose()
        Traceback (most recent call last):
          ...
        ValueError: Current DataFrame has more then the given limit 1000 rows.
        Please set 'compute.max_rows' by using 'pyspark.pandas.config.set_option'
        to retrieve to retrieve more than 1000 rows. Note that, before changing the
        'compute.max_rows', this operation is considerably expensive.

Returns
-------
DataFrame
    The transposed DataFrame.

Notes
-----
Transposing a DataFrame with mixed dtypes will result in a homogeneous
DataFrame with the coerced dtype. For instance, if int and float have
to be placed in same column, it becomes float. If type coercion is not
possible, it fails.

Also, note that the values in index should be unique because they become
unique column names.

In addition, if Spark 2.3 is used, the types should always be exactly same.

Examples
--------
**Square DataFrame with homogeneous dtype**

>>> d1 = {'col1': [1, 2], 'col2': [3, 4]}
>>> df1 = ps.DataFrame(data=d1, columns=['col1', 'col2'])
>>> df1
   col1  col2
0     1     3
1     2     4

>>> df1_transposed = df1.T.sort_index()  # doctest: +SKIP
>>> df1_transposed  # doctest: +SKIP
      0  1
col1  1  2
col2  3  4

When the dtype is homogeneous in the original DataFrame, we get a
transposed DataFrame with the same dtype:

>>> df1.dtypes
col1    int64
col2    int64
dtype: object
>>> df1_transposed.dtypes  # doctest: +SKIP
0    int64
1    int64
dtype: object

**Non-square DataFrame with mixed dtypes**

>>> d2 = {'score': [9.5, 8],
...       'kids': [0, 0],
...       'age': [12, 22]}
>>> df2 = ps.DataFrame(data=d2, columns=['score', 'kids', 'age'])
>>> df2
   score  kids  age
0    9.5     0   12
1    8.0     0   22

>>> df2_transposed = df2.T.sort_index()  # doctest: +SKIP
>>> df2_transposed  # doctest: +SKIP
          0     1
age    12.0  22.0
kids    0.0   0.0
score   9.5   8.0

When the DataFrame has mixed dtypes, we get a transposed DataFrame with
the coerced dtype:

>>> df2.dtypes
score    float64
kids       int64
age        int64
dtype: object

>>> df2_transposed.dtypes  # doctest: +SKIP
0    float64
1    float64
dtype: object
def transpose(self) -> 'DataFrame':
    "\n        Transpose index and columns.\n\n        Reflect the DataFrame over its main diagonal by writing rows as columns\n        and vice-versa. The property :attr:`.T` is an accessor to the method\n        :meth:`transpose`.\n\n        .. note:: This method is based on an expensive operation due to the nature\n            of big data. Internally it needs to generate each row for each value, and\n            then group twice - it is a huge operation. To prevent misusage, this method\n            has the 'compute.max_rows' default limit of input length, and raises a ValueError.\n\n                >>> from pyspark.pandas.config import option_context\n                >>> with option_context('compute.max_rows', 1000):  # doctest: +NORMALIZE_WHITESPACE\n                ...     ps.DataFrame({'a': range(1001)}).transpose()\n                Traceback (most recent call last):\n                  ...\n                ValueError: Current DataFrame has more then the given limit 1000 rows.\n                Please set 'compute.max_rows' by using 'pyspark.pandas.config.set_option'\n                to retrieve to retrieve more than 1000 rows. Note that, before changing the\n                'compute.max_rows', this operation is considerably expensive.\n\n        Returns\n        -------\n        DataFrame\n            The transposed DataFrame.\n\n        Notes\n        -----\n        Transposing a DataFrame with mixed dtypes will result in a homogeneous\n        DataFrame with the coerced dtype. For instance, if int and float have\n        to be placed in same column, it becomes float. If type coercion is not\n        possible, it fails.\n\n        Also, note that the values in index should be unique because they become\n        unique column names.\n\n        In addition, if Spark 2.3 is used, the types should always be exactly same.\n\n        Examples\n        --------\n        **Square DataFrame with homogeneous dtype**\n\n        >>> d1 = {'col1': [1, 2], 'col2': [3, 4]}\n        >>> df1 = ps.DataFrame(data=d1, columns=['col1', 'col2'])\n        >>> df1\n           col1  col2\n        0     1     3\n        1     2     4\n\n        >>> df1_transposed = df1.T.sort_index()  # doctest: +SKIP\n        >>> df1_transposed  # doctest: +SKIP\n              0  1\n        col1  1  2\n        col2  3  4\n\n        When the dtype is homogeneous in the original DataFrame, we get a\n        transposed DataFrame with the same dtype:\n\n        >>> df1.dtypes\n        col1    int64\n        col2    int64\n        dtype: object\n        >>> df1_transposed.dtypes  # doctest: +SKIP\n        0    int64\n        1    int64\n        dtype: object\n\n        **Non-square DataFrame with mixed dtypes**\n\n        >>> d2 = {'score': [9.5, 8],\n        ...       'kids': [0, 0],\n        ...       'age': [12, 22]}\n        >>> df2 = ps.DataFrame(data=d2, columns=['score', 'kids', 'age'])\n        >>> df2\n           score  kids  age\n        0    9.5     0   12\n        1    8.0     0   22\n\n        >>> df2_transposed = df2.T.sort_index()  # doctest: +SKIP\n        >>> df2_transposed  # doctest: +SKIP\n                  0     1\n        age    12.0  22.0\n        kids    0.0   0.0\n        score   9.5   8.0\n\n        When the DataFrame has mixed dtypes, we get a transposed DataFrame with\n        the coerced dtype:\n\n        >>> df2.dtypes\n        score    float64\n        kids       int64\n        age        int64\n        dtype: object\n\n        >>> df2_transposed.dtypes  # doctest: +SKIP\n        0    float64\n        1    float64\n        dtype: object\n        "
    max_compute_count = get_option('compute.max_rows')
    if (max_compute_count is not None):
        pdf = self.head((max_compute_count + 1))._to_internal_pandas()
        if (len(pdf) > max_compute_count):
            raise ValueError("Current DataFrame has more then the given limit {0} rows. Please set 'compute.max_rows' by using 'pyspark.pandas.config.set_option' to retrieve to retrieve more than {0} rows. Note that, before changing the 'compute.max_rows', this operation is considerably expensive.".format(max_compute_count))
        return DataFrame(pdf.transpose())
    pairs = F.explode(F.array(*[F.struct(*[SF.lit(col).alias(SPARK_INDEX_NAME_FORMAT(i)) for (i, col) in enumerate(label)], *[self._internal.spark_column_for(label).alias('value')]) for label in self._internal.column_labels]))
    exploded_df = self._internal.spark_frame.withColumn('pairs', pairs).select([F.to_json(F.struct(F.array(*[scol for scol in self._internal.index_spark_columns]).alias('a'))).alias('index'), F.col('pairs.*')])
    internal_index_columns = [SPARK_INDEX_NAME_FORMAT(i) for i in range(self._internal.column_labels_level)]
    pivoted_df = exploded_df.groupBy(internal_index_columns).pivot('index')
    transposed_df = pivoted_df.agg(F.first(F.col('value')))
    new_data_columns = list(filter((lambda x: (x not in internal_index_columns)), transposed_df.columns))
    column_labels = [(None if ((len(label) == 1) and (label[0] is None)) else label) for label in (tuple(json.loads(col)['a']) for col in new_data_columns)]
    internal = InternalFrame(spark_frame=transposed_df, index_spark_columns=[scol_for(transposed_df, col) for col in internal_index_columns], index_names=self._internal.column_label_names, column_labels=column_labels, data_spark_columns=[scol_for(transposed_df, col) for col in new_data_columns], column_label_names=self._internal.index_names)
    return DataFrame(internal)