Spaces:
Sleeping
Sleeping
juanmartip95
commited on
Commit
•
eec1ef5
1
Parent(s):
19b1e5c
Update utils.py
Browse files
utils.py
CHANGED
@@ -25,6 +25,7 @@ def load_and_preprocess_data():
|
|
25 |
# Use only positive quantites. This is not a robust approach,
|
26 |
# but to keep things simple it quite good.
|
27 |
df = df[df["Book-Rating"] > 0]
|
|
|
28 |
|
29 |
# Parse the date column and add 10 years, just to better visualization
|
30 |
#df["InvoiceDate"] = pd.to_datetime(df["InvoiceDate"]).dt.floor( "d") + pd.offsets.DateOffset(years=10)
|
@@ -54,9 +55,7 @@ def load_and_preprocess_data():
|
|
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
|
58 |
-
#df["CustomerIndex"] = user_idx
|
59 |
-
|
60 |
# Merging both DataFrames based on respective common columns
|
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')
|
|
|
25 |
# Use only positive quantites. This is not a robust approach,
|
26 |
# but to keep things simple it quite good.
|
27 |
df = df[df["Book-Rating"] > 0]
|
28 |
+
|
29 |
|
30 |
# Parse the date column and add 10 years, just to better visualization
|
31 |
#df["InvoiceDate"] = pd.to_datetime(df["InvoiceDate"]).dt.floor( "d") + pd.offsets.DateOffset(years=10)
|
|
|
55 |
user_idx = df["User-ID"].astype(product_cat).cat.codes
|
56 |
product_idx = df["ISBN"].astype(product_cat).cat.codes
|
57 |
|
58 |
+
# Add the categorical index to the starting dataframe
|
|
|
|
|
59 |
# Merging both DataFrames based on respective common columns
|
60 |
merged_df = pd.merge(df, df_users[['User-ID', 'Location', 'Age']], on='User-ID', how='left')
|
61 |
merged_df = pd.merge(merged_df, df_books[['ISBN', 'Book-Title', 'Book-Author', 'Year-Of-Publication']], on='ISBN', how='left')
|