I use groupby and apply a lot in my programs. However, I encountered an error I could not really understand: My apply goes through ALL of my pandas-groupby groups twice.