Can anyone provide an explanation of what it means to have a "slice" vs. a "copy" in pandas? I've been working with pandas for a while, and have internalized some rules of thumb about how to avoid the warnings.
But a colleague had some weird behavior today that I think is traceable to the same distinction, and it made me realize that I don't really understand what's going on under the hood and how it plays out in different situation. I'd love an explanation!
--
Today's example:
def func(df):
df.sort('sort_col',inplace=True)
some other stuff
return modified_df
grouped = df.groupby('col1')
result = grouped.apply(func)
func
ended up returning the same modified_df
each time, until we changed the sort
to df2 = df.sort('sort_col').copy()
. I think this has to do with "By default the group keys are sorted during the groupby operation" from the pandas docs....but I'm confused about what exactly is happening.
Thanks!