Pandas, Future Warning: Indexing with multiple keys

This warning was introduced in pandas 1.0.0, following a discussion on GitHub. So best use what was suggested there:

df.groupby([0, 1])[[1, 2]].apply(sum)

It's also possible to move the slicing operation to the end, but that is not as efficient:

df.groupby([0, 1]).apply(sum).loc[:, 1:]

Thanks @ALollz and @cmosig for helpful comments.


Use double brackets after the groupby method. Single brackets are used to output a Pandas Series and double brackets are used to output a Pandas DataFrame.

df.groupby([0,1])[[1,2]].apply(sum)

Tags:

Python

Pandas