Skip to content

Instantly share code, notes, and snippets.

@ikatsov
Created March 15, 2020 15:54
Show Gist options
  • Save ikatsov/155bafe7b99e2fe093a25b2de7ad8535 to your computer and use it in GitHub Desktop.
Save ikatsov/155bafe7b99e2fe093a25b2de7ad8535 to your computer and use it in GitHub Desktop.
order_ds = orders_csv.merge(order_products_csv,
left_on='order_id',
right_index=True)
# Creating sequences based on transactions
order_product_list = order_ds.sort_values(
['user_id','order_id','add_to_cart_order'])
[['order_id','product_id']].values.tolist()
# Each entry of a corpus is one order represented by
# a chronologically sorted sequence of product IDs.
product_corpus = []
sentence = []
new_order_id = order_product_list[0][0]
for (order_id, product_id) in order_product_list:
if new_order_id != order_id:
product_corpus.append(sentence)
sentence = []
new_order_id = order_id
sentence.append(str(product_id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment