Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas `replace` * in signature

Following is the signature for the replace method in Pandas API (https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.replace.html)

DataFrame.replace(to_replace=None, value=_NoDefault.no_default, *, 
     inplace=False, limit=None, regex=False, method=_NoDefault.no_default)

While I understand the API method, I do not understand what does that * refer to in the arguments string. My guess would be that it is something related to *args. Perhaps *-like notation can be used after the second argument, but I wanted some clarity on this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is to make all arguments after it keyword only. The * catches the third and more unnamed parameters.

Thus in this method, only to_replace and value can be passed directly:

df.replace('a', 'b')

had been transitioning from classical ordered parameter to keyword-only for many methods lately. This improves on usability/readability for many cases. For instance pivot/pivot_table have so far similar parameters but in a different order, which makes it difficult to remember. In the future, enforcing keyword-only will make it unambiguous.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading