import pandas as pd
import numpy as np
from collections import Counter
import ast
from [Link] import data_table
from [Link] import drive
data_table.enable_dataframe_formatter()
[Link]("/content/drive", force_remount=True)
b = ’/content/drive/My Drive/csvfiles/[Link]’
books = pd.read_csv(b)
[Link](1)
[Link]()
[Link]
[Link]
[Link](’Unnamed: 0’,axis=1,inplace=True)
[Link]().sum()
[Link]().sum()
no_desc = "Description not available"
[Link](no_desc,inplace=True)
[Link]().sum()
books.Num_Ratings.dtype
books[’Num_Ratings’] = books[’Num_Ratings’].[Link](’,’,’’).astype(int)
Selecting and filtering books
popular_books = popular_books.sort_values(’Avg_Rating’,ascending=False).head(100)
popular_books = popular_books.drop_duplicates(’Book’)[[’Book’,’Author’,’Description’,’Avg_Rating’,’Num_
Ratings’,’URL’]]
popular_books = popular_books.head(50)
popular_books
Genre-Based Book Recommendation
def recommend():
books = pd.read_csv(b)
user_input = input("\nEnter genres (comma-separated): ")
user_genres = [[Link]().capitalize() for genre in user_input.split(’,’)]
books[’Num_Ratings’] = books[’Num_Ratings’].[Link](’,’, ’’).astype(int)
filtered_books = books[books[’Genres’].apply(lambda x: all(genre in x for genre in user_genres))]
top_num_ratings = filtered_books[filtered_books[’Num_Ratings’] >= 900000]
top_100 = top_num_ratings.sort_values(’Avg_Rating’, ascending=False).head(100)
top_no_duplicates = top_100.drop_duplicates(’Book’)[[’Book’, ’Author’, ’Description’, ’Avg_Rating’, ’Nu
m_Ratings’, ’URL’]]
top_no_duplicates = top_no_duplicates.head(5)
top_output = top_no_duplicates[[’Book’, ’Author’, ’Description’, ’URL’]]
display(top_output)
recommend()