Skip to content
Advertisement

Python – Getting keyError(key) when using groupBy.agg()

JavaScript

When I try to use the agg function, I’m getting raise KeyError(key) from err.

What I”m trying to do is combine these based on the columns I’m grouping by and I want to take the first dict after grouping.

I want the output to be what you see below and I don’t really care which “GM” is kept. I arbitrarily chose the first, which is fine.

JavaScript

Advertisement

Answer

Use .iloc:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement