I have pandas DataFrame with the following columns:
- VisitorID (unique for each user - cookie based)
- VisitNumber (1 = first visit, 2 = second visit and etc...)
- TimeSpentOnVist (visit duration in seconds)
- Channel (the referrer of the visit. ex: Facebook, Google and Bing )
- Media type (paid or organic)
The visitor ID is repeating for each visit (1, 2, 3). I would like to aggregate it considering the last visit for channel and media type, but at the same time, aggregate (summing up) the timespent across all the visits. My goal is to group by the visitorID so there is no duplication.
What is the most efficient way to perform this aggregation in Pandas ?