For:
df = pd.DataFrame({'a': (1,1,2,3,3), 'b':(20,21,30,40,41)})
Why is only this working
df['b_new'] = df.a.map(df.groupby('a').b.nth(-1))
but not:
>>df['b_new'] = df.a.map(df.groupby('a').nth(-1))
...
TypeError: 'DataFrame' object is not callable
although both:
>>df.groupby('a').b.nth(-1)
b
a
1 21
2 30
3 41
and
df.groupby('a').nth(-1)
-
b
a
1 21
2 30
3 41
do deliver quite similar results.
(see also: https://stackoverflow.com/a/47924467/7450524