Type df.T ??
in ipython for help.
>>> df = pd.DataFrame()
>>> df.T??
Type:
property
String form: <property object at 0x7f1aa67d6540>
Source:
# df.T.fget
def transpose(self, *args, copy: bool = False) -> "DataFrame":
"""
Transpose index and columns.
(snip...)
df.T
seems to be the same asdf.transpose ()
.
I could only see the same help with df.transpose ??
, so I grep the source code and tried my best to find it.
It seems that it is registered so that self.transepose ()
can be called as self.T
using the built-in function property
as shown below.
Python Documentation built-in functions property
python:/opt/miniconda3/lib/python3.8/site-packages/pandas/core/base.py
from pandas.compat.numpy import function as nv
(snip...)
class IndexOpsMixin:
(snip...)
def transpose(self, *args, **kwargs):
"""
Return the transpose, which is by definition self.
Returns
-------
%(klass)s
"""
nv.validate_transpose(args, kwargs)
return self
T = property(
transpose,
doc="""
Return the transpose, which is by definition self.
""",
)
(snip...)
The first argument of property is a function to get the attribute value. ... Yeah, I can't put it into my own words, but I was able to do what I wanted to do, so I hope I can understand it someday.
Recommended Posts