[Python] [pandas] How is pd.DataFrame (). T implemented?

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

[Python] [pandas] How is pd.DataFrame (). T implemented?
How Python __dict__ is used
[Python] How to use Pandas Series
[Python] What is pandas Series and DataFrame?
[Python] Summary of how to use pandas
[Pandas] What is set_option [How to use]
How to use is and == in Python
Python is easy
My pandas (python)
[Python] How to read excel file with pandas
What is python
Python is instance
python pandas notes
What is Python
[Python] How to run Jupyter-notebook + pandas + multiprocessing (Pool) [pandas] Memo
How to convert JSON file to CSV file with Python Pandas
[Python] How to deal with pandas read_html read error
[Python] pandas Code that is likely to be reused
I tried to summarize how to use pandas in python
python int is infinite
How to install Python
How to use Pandas 2
Implemented SimRank in Python
Python Not Implemented Error
How to install python
Implemented Matrix Factorization (python)
Installing pandas on python2.6
I implemented Python Logging
pandas idxmax is slow
Implemented Shiritori in Python
[Python] What is virtualenv
Python application: Pandas # 3: Dataframe
How tuples work | Python
Python Basic --Pandas, Numpy-
How to test that Exception is raised in python unittest
Differences in sys.path depending on how Python is started (v3.8.2)
[Python] How to output a pandas table to an excel file
How to read an Excel file (.xlsx) with Pandas [Python]
Data science companion in python, how to specify elements in pandas