forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add code sample for pandas-dev#41999
- Loading branch information
1 parent
4ae8563
commit 76b7f32
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# BUG?: 1.3 behavior change with groupby, apply and side effect #41999 | ||
|
||
import pandas as pd | ||
|
||
print(pd.__version__) | ||
|
||
|
||
def apply_func(df): | ||
del df["MEMBER_ID"] | ||
|
||
return df.head(1) | ||
|
||
|
||
df = pd.DataFrame.from_dict( | ||
{ | ||
"MONTH": {0: "April", 1: "April", 2: "April"}, | ||
"MEMBER_ID": {0: "Member A", 1: "Member A", 2: "Member B"}, | ||
"ACTIVITY_CATEGORY": { | ||
0: "Activity 1", | ||
1: "Days off at homebase", | ||
2: "Activity 1", | ||
}, | ||
"FTE": {0: 1.0, 1: 1.0, 2: 0.75}, | ||
"FTE_OFF_DAYS": {0: 5, 1: 5, 2: 10}, | ||
} | ||
) | ||
grp = df.groupby(["MONTH", "FTE"], observed=True)[ | ||
["MEMBER_ID", "FTE_OFF_DAYS", "ACTIVITY_CATEGORY"] | ||
] | ||
result = grp.apply(apply_func) | ||
print(result) |