Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between transpose() and .T in Pandas

Tags:

python

pandas

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:

  • Pandas | API documentation | pandas.DataFrame.transpose
like image 744
Taras Avatar asked Sep 10 '25 16:09

Taras


1 Answers

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)
like image 89
Xukrao Avatar answered Sep 13 '25 06:09

Xukrao