I have a table with users and times of their actions
user_ id | time | user_action |
---|---|---|
user_1 | 1 | action_1 |
user_2 | 2 | action_2 |
user_1 | 3 | action_3 |
user_2 | 4 | action_4 |
My algorithm includes looping over unique values and making some actions using shift function.
users = df.user_id.unique()
for user in users:
df_new = df[df.user_id == user]
df_new['...'] = df['user_action'].shift(1)....
some actions using shift
Also cumsums are used, so it would be impossible to implement algorithm without dividing into “df_new” pieces
This method is too long seemingly because of using Python’s “for”. How can I do it using build-in Pandas functions?