Skip to content

Commit

Permalink
add code sample for pandas-dev#41999
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjayhawkins committed Jun 14, 2021
1 parent 4ae8563 commit 76b7f32
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bisect/41999.py
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)

0 comments on commit 76b7f32

Please sign in to comment.