I am having trouble with applying a customer function to a dataframe. The function works fine and returns the correct dataframe. However, after having it applied my dataframe is still the old one.
My DataFrame is like this:
d = {'col 1' : ['a', 'a', 'a', 'b', 'b', 'b'],'col 2' : [1, 1, 2, 2, 1, 2]}
df = pd.DataFrame(data = d)
df.set_index('col 1')
I wrote a little test function to group by col 1 and find the highest value in col 2 for each group:
def tester(x):
x = x.groupby('col 1', group_keys=False).apply(lambda x: x.nlargest(1, 'col 2'))
return x
then using the function on my dataframe returns the correctly grouped result:
tester(df)
However outside the function the df is still the old one. Why does this happen? This behavior does not occur with lists or dictionaries for instance. How can I continue working with the manipulated df after the function?
Thanks!

