3

I have a sample of data:

d = {'name': ['Alice', 'Bob'], 'score': [9.5, 8], 'kids': [1, 2]}

I want to display simple statistics of the dataset in pandas using describe() method.

df = pd.DataFrame(data=d)
print(df.describe().transpose())

Output 1:

result_1

Is there any difference between the two workflows when I am ending up with the same result?

df = pd.DataFrame(data=d)
print(df.describe().T)

Output 2:

result_1


References:

Taras
  • 266
  • 6
  • 23
  • 5
    the property T is an accessor to the method transpose(). – BENY Feb 17 '19 at 15:59
  • 4
    Did you read the documentation of [T](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.T.html#pandas.DataFrame.T) ? _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().**_ – Patrick Artner Feb 17 '19 at 15:59

1 Answers1

9

There is no difference. As mentioned in the T attribute documentation, T is simply an accessor for the transpose() method. Indeed a quick look in the pandas DataFrame source code shows that the entire implementation of T is nothing more than:

T = property(transpose)
Xukrao
  • 8,003
  • 5
  • 26
  • 52