I have a dataseta with users, visit_types (bookings or searches) and hotels. I need to populate a new column with the most booked hotel, based on previous booked hotel for that row.
For example,
**user** **visit_type** **hotel_code** **most_booked**
1 user1 search 1 NaN
2 user1 search 2 NaN
3 user1 booking 1 NaN
4 user1 search 8 NaN
5 user1 booking 8 1
6 user2 search 6 NaN
7 user2 booking 6 NaN
8 user2 search 4 NaN
9 user2 booking 4 6
10 user2 booking 6 4
11 user2 booking 4 6
So with this example:
The most booked hotel for user1 would be, in row 3 hotel = NaN, beacuse it has no hotel booked previously, and in row 5 it would be hotel = 1.
For user2, row 7 would be hotel = NaN, row 9 would be hotel = 6, and row 10 hotel = 4 (as it is the last booked and there are only two hotels booked) and for the last row 11, the hotel would be 6 as it is the most booked up to that point (without taking into account row 11).