juanmartip95 commited on
Commit
19b1e5c
1 Parent(s): f7d18eb

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +3 -2
utils.py CHANGED
@@ -47,11 +47,11 @@ def load_and_preprocess_data():
47
 
48
  # Create a categorical type for users and product. User ordered to ensure
49
  # reproducibility
50
- #user_cat = pd.CategoricalDtype(categories=sorted(users), ordered=True)
51
  product_cat = pd.CategoricalDtype(categories=sorted(products), ordered=True)
52
 
53
  # Transform and get the indexes of the columns
54
- user_idx = df["User-ID"]
55
  product_idx = df["ISBN"].astype(product_cat).cat.codes
56
 
57
  # Add the categorical index to the starting dataframe
@@ -61,6 +61,7 @@ def load_and_preprocess_data():
61
  merged_df = pd.merge(df, df_users[['User-ID', 'Location', 'Age']], on='User-ID', how='left')
62
  merged_df = pd.merge(merged_df, df_books[['ISBN', 'Book-Title', 'Book-Author', 'Year-Of-Publication']], on='ISBN', how='left')
63
  merged_df["ProductIndex"] = product_idx
 
64
 
65
 
66
 
 
47
 
48
  # Create a categorical type for users and product. User ordered to ensure
49
  # reproducibility
50
+ user_cat = pd.CategoricalDtype(categories=sorted(users), ordered=True)
51
  product_cat = pd.CategoricalDtype(categories=sorted(products), ordered=True)
52
 
53
  # Transform and get the indexes of the columns
54
+ user_idx = df["User-ID"].astype(product_cat).cat.codes
55
  product_idx = df["ISBN"].astype(product_cat).cat.codes
56
 
57
  # Add the categorical index to the starting dataframe
 
61
  merged_df = pd.merge(df, df_users[['User-ID', 'Location', 'Age']], on='User-ID', how='left')
62
  merged_df = pd.merge(merged_df, df_books[['ISBN', 'Book-Title', 'Book-Author', 'Year-Of-Publication']], on='ISBN', how='left')
63
  merged_df["ProductIndex"] = product_idx
64
+ merged_df["CustomerIndex"] = user_idx
65
 
66
 
67