From 38b11b56036e984ffdb00a1d5a6c91a7362e9cb5 Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla Date: Sun, 20 Aug 2023 19:32:27 +0530 Subject: [PATCH 1/3] Updated map method documentation Added an example for standard functions for the map function --- pandas/core/frame.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 25fc5bd6664f5..34d18803c362c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10085,6 +10085,20 @@ def map( 0 3 4 1 5 5 + >>> def foo(x): + if x > 2.5: + x = 2 + + elif x <= 2.5: + x = 1 + + return x + + >>> df.map(foo) + 0 1 + 0 1 1 + 1 2 2 + Like Series.map, NA values can be ignored: >>> df_copy = df.copy() From 6f40da17ba224c7a7f634a34c22beb166f8bb300 Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla Date: Sun, 20 Aug 2023 20:05:48 +0530 Subject: [PATCH 2/3] Updated Documentation for the map method Added documentation for extra keyword arguments in the map method --- pandas/core/frame.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 34d18803c362c..c7cd2fba9582d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10085,16 +10085,16 @@ def map( 0 3 4 1 5 5 - >>> def foo(x): - if x > 2.5: + >>> def func(x,y): # x refers to the element in the DataFrame + if x > y: x = 2 - elif x <= 2.5: + elif x <= y: x = 1 return x - >>> df.map(foo) + >>> df.map(func, y=2.5) 0 1 0 1 1 1 2 2 From db413952d64fb9ea1d0871b358fd02c105cf4578 Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla Date: Wed, 30 Aug 2023 22:20:12 +0530 Subject: [PATCH 3/3] Modified initial docstring commit Used round function instead of defining a function in the example --- pandas/core/frame.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c7cd2fba9582d..09a6fc3e77396 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10084,20 +10084,11 @@ def map( 0 1 0 3 4 1 5 5 - - >>> def func(x,y): # x refers to the element in the DataFrame - 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 + >>> df.map(round, digits=2) + 0 1 + 0 1.00 2.12 + 1 3.36 4.57 Like Series.map, NA values can be ignored: