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`. Parameters ---------- *args : tuple, optional
(
self,
*args,
copy: bool | lib.NoDefault = lib.no_default,
)
| 4073 | return result |
| 4074 | |
| 4075 | def transpose( |
| 4076 | self, |
| 4077 | *args, |
| 4078 | copy: bool | lib.NoDefault = lib.no_default, |
| 4079 | ) -> DataFrame: |
| 4080 | """ |
| 4081 | Transpose index and columns. |
| 4082 | |
| 4083 | Reflect the DataFrame over its main diagonal by writing rows as columns |
| 4084 | and vice-versa. The property :attr:`.T` is an accessor to the method |
| 4085 | :meth:`transpose`. |
| 4086 | |
| 4087 | Parameters |
| 4088 | ---------- |
| 4089 | *args : tuple, optional |
| 4090 | Accepted for compatibility with NumPy. |
| 4091 | copy : bool, default False |
| 4092 | This keyword is now ignored; changing its value will have no |
| 4093 | impact on the method. |
| 4094 | |
| 4095 | Note that a copy is always required for mixed dtype DataFrames, |
| 4096 | or for DataFrames with any extension types. |
| 4097 | |
| 4098 | .. deprecated:: 3.0.0 |
| 4099 | |
| 4100 | This keyword is ignored and will be removed in pandas 4.0. Since |
| 4101 | pandas 3.0, this method always returns a new object using a lazy |
| 4102 | copy mechanism that defers copies until necessary |
| 4103 | (Copy-on-Write). See the `user guide on Copy-on-Write |
| 4104 | <https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__ |
| 4105 | for more details. |
| 4106 | |
| 4107 | Returns |
| 4108 | ------- |
| 4109 | DataFrame |
| 4110 | The transposed DataFrame. |
| 4111 | |
| 4112 | See Also |
| 4113 | -------- |
| 4114 | numpy.transpose : Permute the dimensions of a given array. |
| 4115 | |
| 4116 | Notes |
| 4117 | ----- |
| 4118 | Transposing a DataFrame with mixed dtypes will result in a homogeneous |
| 4119 | DataFrame with the `object` dtype. In such a case, a copy of the data |
| 4120 | is always made. |
| 4121 | |
| 4122 | Examples |
| 4123 | -------- |
| 4124 | **Square DataFrame with homogeneous dtype** |
| 4125 | |
| 4126 | >>> d1 = {"col1": [1, 2], "col2": [3, 4]} |
| 4127 | >>> df1 = pd.DataFrame(data=d1) |
| 4128 | >>> df1 |
| 4129 | col1 col2 |
| 4130 | 0 1 3 |
| 4131 | 1 2 4 |
| 4132 |