Skip to content

Updated documentation for pandas.DataFrame.map #54649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10088,6 +10088,20 @@ def map(
0 3 4
1 5 5

>>> def func(x,y): # x refers to the element in the DataFrame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just define a lambda that takes an extra argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually my goal was to demonstrate how the map function can be used with standard functions that are not lambdas. If you think I should use a more complex example to show that, I could do so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just provide a built in function like round?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the advice! I did just that, you can have a look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Looks like some code checks are failing in the CI

if x > y:
x = 2

elif x <= y:
x = 1

return x

>>> df.map(func, y=2.5)
0 1
0 1 1
1 2 2

Like Series.map, NA values can be ignored:

>>> df_copy = df.copy()
Expand Down