Skip to content

Instantly share code, notes, and snippets.

@ikatsov
Created March 15, 2020 16:39
Show Gist options
  • Save ikatsov/c04707548f2903c19a0350d1c66c4b2e to your computer and use it in GitHub Desktop.
Save ikatsov/c04707548f2903c19a0350d1c66c4b2e to your computer and use it in GitHub Desktop.
orders.sort_values(by=['user_id','order_number','add_to_cart_order'],
inplace=True)
orders_by_uid = orders.groupby("user_id")
.apply(lambda order: ' '.join(order['product_id'].tolist()))
orders_by_uid = pd.DataFrame(orders_by_uid,
columns=['all_orders'])
orders_by_uid.reset_index(inplace=True)
orders_by_uid.user_id = orders_by_uid.user_id.astype(str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment