What's the difference between a method and an accessor to a method?

Screen Link: https://app.dataquest.io/m/370/working-with-missing-data/2/verifying-the-total-columns

This lesson uses the following code to transpose a DataFrame:

null_df = pd.DataFrame({'null_counts': null_counts, 'null_pct': null_counts_pct})
# Rotate the dataframe so that rows become columns and vice-versa
null_df = null_df.T.astype(int)

print(null_df)

I understand what it’s trying to do, I just don’t understand why it used pandas.DataFrame.T instead of pandas.DataFrame.transpose().

The documentation for pandas.DataFrame.T says that it’s "an accessor to the method transpose()". I’m not sure what that means. What’s the difference between a method and an accessor to a method?

Thanks in advance.

1 Like

In their usage, there isn’t any difference, as far as I can tell.

The major differences happen in the implementation. I was unable to find a formal definition of accessor. I believe the section Extending pandas in the documentation is the closest there is to a definition, and we need to infer one from it.

The definition I came up with is that an accessor is any object created by classes implemented using any of the following decorator classes:

I hope this helps.

4 Likes

That is helpful, thanks.

1 Like

Found this information that may be helpful as I was wondering the same thing.

I kind of imagine an accessor to be like a skybridge that extends a library’s functionality by connecting it to another library. In our case here, pandas provides decorators to extend its functionality thus we are able to access functions and methods of the Python datetime module.

This way we don’t need to step out of building A to get to building B, we can just access building B through the skybridge that connects building A and building B.

1 Like