You are viewing documentation about an older version (1.18.0). View latest version

modin.pandas.DataFrame.transpose¶

DataFrame.transpose(copy=False, *args)[source]¶

Transpose index and columns.

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

Parameters:
  • tuple (*args) – Accepted for compatibility with NumPy. Note these arguments are ignored in the snowpark pandas implementation unless go through a fallback path, in which case they may be used by the native pandas implementation.

  • optional – Accepted for compatibility with NumPy. Note these arguments are ignored in the snowpark pandas implementation unless go through a fallback path, in which case they may be used by the native pandas implementation.

  • bool (copy) – Whether to copy the data after transposing, even for DataFrames with a single dtype. The snowpark pandas implementation ignores this parameter.

  • False (default) – Whether to copy the data after transposing, even for DataFrames with a single dtype. The snowpark pandas implementation ignores this parameter.

  • DataFrames (Note that a copy is always required for mixed dtype) –

  • types. (or for DataFrames with any extension) –

Returns:

DataFrame

The transposed DataFrame.

Examples::

Square DataFrame with homogeneous dtype

>>> d1 = {'col1': [1, 2], 'col2': [3, 4]}
>>> df1 = pd.DataFrame(data=d1)
>>> df1
   col1  col2
0     1     3
1     2     4
Copy
>>> df1_transposed = df1.T  # or df1.transpose()
>>> df1_transposed
      0  1
col1  1  2
col2  3  4
Copy

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
Copy
>>> df1_transposed.dtypes
0    int64
1    int64
dtype: object
Copy

Non-square DataFrame with mixed dtypes

>>> d2 = {'name': ['Alice', 'Bob'],
...      'score': [9.5, 8],
...      'employed': [False, True],
...       'kids': [0, 0]}
>>> df2 = pd.DataFrame(data=d2)
>>> df2
    name  score  employed  kids
0  Alice    9.5     False     0
1    Bob    8.0      True     0
Copy
>>> df2_transposed = df2.T  # or df2.transpose()
>>> df2_transposed
              0     1
name      Alice   Bob
score       9.5   8.0
employed  False  True
kids          0     0
Copy

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

>>> df2.dtypes
name         object
score       float64
employed       bool
kids          int64
dtype: object
Copy
>>> df2_transposed.dtypes
0    object
1    object
dtype: object
Copy