|
| 1 | +import pandas as pd |
| 2 | + |
| 3 | +tags = pd.read_csv('/Users/siyaksares/Developer/GitHub/ReadersRadarProject/tags.csv') |
| 4 | +book_tags = pd.read_csv('/Users/siyaksares/Developer/GitHub/ReadersRadarProject/book_tags.csv') |
| 5 | + |
| 6 | +tags['tag_id'] = pd.to_numeric(tags['tag_id'], errors='coerce') |
| 7 | +book_tags['tag_id'] = pd.to_numeric(book_tags['tag_id'], errors='coerce') |
| 8 | + |
| 9 | +tags.dropna(subset=['tag_id'], inplace=True) |
| 10 | +book_tags.dropna(subset=['tag_id'], inplace=True) |
| 11 | + |
| 12 | +top_tags = book_tags.groupby('tag_id').count().sort_values(by='count', ascending=False).head(10) |
| 13 | +top_tag_names = tags[tags['tag_id'].isin(top_tags.index)]['tag_name'] |
| 14 | + |
| 15 | +print("Top 10 Most Used Tags:") |
| 16 | +print(top_tag_names) |
| 17 | + |
| 18 | +''' |
| 19 | +selected_tag = input("Please select a tag: ") # Strip whitespace from the input |
| 20 | +print("Selected tag:", selected_tag) |
| 21 | + |
| 22 | +if not selected_tag: |
| 23 | + print("No tag selected. Please enter a tag.") |
| 24 | +elif selected_tag not in top_tag_names.values: |
| 25 | + print("Invalid label. Please select a tag from the top 10 most used tags.") |
| 26 | +else: |
| 27 | + selected_tag_id = tags[tags['tag_name'] == selected_tag]['tag_id'].values[0] |
| 28 | + filtered_books = book_tags[book_tags['tag_id'] == selected_tag_id] |
| 29 | + if not filtered_books.empty: |
| 30 | + random_book_id = filtered_books.sample(1)['goodreads_book_id'].values[0] |
| 31 | + books = pd.read_csv('books.csv') |
| 32 | + selected_book = books[books['book_id'] == random_book_id][['title']] |
| 33 | + print("Selected Book:") |
| 34 | + print(selected_book) |
| 35 | + else: |
| 36 | + print("No books were found associated with the selected tag.")''' |
| 37 | + |
| 38 | +''' |
| 39 | +selected_tag = input("Please select a tag: ") # Strip whitespace from the input |
| 40 | +print("Selected tag:", selected_tag) |
| 41 | + |
| 42 | +if not selected_tag: |
| 43 | + print("No tag selected. Please enter a tag.") |
| 44 | +elif selected_tag not in top_tag_names.values: |
| 45 | + print("Invalid label. Please select a tag from the top 10 most used tags.") |
| 46 | +else: |
| 47 | + selected_tag_id = tags[tags['tag_name'] == selected_tag]['tag_id'].values[0] |
| 48 | + filtered_books = book_tags[book_tags['tag_id'] == selected_tag_id] |
| 49 | + if not filtered_books.empty: |
| 50 | + random_book_id = filtered_books.sample(1)['goodreads_book_id'].values[0] |
| 51 | + books = pd.read_csv('books.csv') |
| 52 | + selected_book = books[books['book_id'] == random_book_id][['title']] |
| 53 | + print("Selected Book:") |
| 54 | + print(selected_book) |
| 55 | + else: |
| 56 | + print("No books were found associated with the selected tag.") |
| 57 | +''' |
| 58 | + |
| 59 | +''' |
| 60 | +selected_tag_lower = selected_tag.lower() # Convert selected tag to lowercase |
| 61 | + |
| 62 | +if not selected_tag_lower: |
| 63 | + print("No tag selected. Please enter a tag.") |
| 64 | +elif selected_tag_lower not in top_tag_names.str.lower().values: # Convert tag names to lowercase for comparison |
| 65 | + print("Invalid label. Please select a tag from the top 10 most used tags.") |
| 66 | +else: |
| 67 | + filtered_books = book_tags[book_tags['tag_name'].str.lower().str.contains(selected_tag_lower)] |
| 68 | + if not filtered_books.empty: |
| 69 | + random_book_id = filtered_books.sample(1)['goodreads_book_id'].values[0] |
| 70 | + books = pd.read_csv('books.csv') |
| 71 | + selected_book = books[books['book_id'] == random_book_id][['title']] |
| 72 | + print("Selected Book:") |
| 73 | + print(selected_book) |
| 74 | + else: |
| 75 | + print("No books were found associated with the selected tag.")''' |
| 76 | + |
| 77 | +''' |
| 78 | +selected_tag = input("Please select a tag: ") # Strip whitespace from the input |
| 79 | +print("Selected tag:", selected_tag) |
| 80 | + |
| 81 | +if not selected_tag: |
| 82 | + print("No tag selected. Please enter a tag.") |
| 83 | +elif selected_tag_lower not in top_tag_names.str.lower().values: # Convert tag names to lowercase for comparison |
| 84 | + print("Invalid label. Please select a tag from the top 10 most used tags.") |
| 85 | +else: |
| 86 | + selected_tag_lower = selected_tag.lower() # Convert selected tag to lowercase |
| 87 | + selected_tag_id = tags[tags['tag_name'].str.lower() == selected_tag_lower]['tag_id'].values[0] |
| 88 | + filtered_books = book_tags[book_tags['tag_id'] == selected_tag_id] |
| 89 | + if not filtered_books.empty: |
| 90 | + random_book_id = filtered_books.sample(1)['goodreads_book_id'].values[0] |
| 91 | + books = pd.read_csv('books.csv') |
| 92 | + selected_book = books[books['book_id'] == random_book_id][['title']] |
| 93 | + print("Selected Book:") |
| 94 | + print(selected_book) |
| 95 | + else: |
| 96 | + print("No books were found associated with the selected tag.")''' |
| 97 | + |
| 98 | +''' |
| 99 | +selected_tag = input("Please select a tag: ") # Strip whitespace from the input |
| 100 | +print("Selected tag:", selected_tag) |
| 101 | + |
| 102 | +if not selected_tag: |
| 103 | + print("No tag selected. Please enter a tag.") |
| 104 | +elif selected_tag_lower not in top_tag_names.str.lower().values: # Convert tag names to lowercase for comparison |
| 105 | + print("Invalid label. Please select a tag from the top 10 most used tags.") |
| 106 | +else: |
| 107 | + selected_tag_lower = selected_tag.lower() # Convert selected tag to lowercase |
| 108 | + selected_tag_id_series = tags[tags['tag_name'].str.lower() == selected_tag_lower]['tag_id'] |
| 109 | + if not selected_tag_id_series.empty: |
| 110 | + selected_tag_id = selected_tag_id_series.values[0] |
| 111 | + filtered_books = book_tags[book_tags['tag_id'] == selected_tag_id] |
| 112 | + if not filtered_books.empty: |
| 113 | + random_book_id = filtered_books.sample(1)['goodreads_book_id'].values[0] |
| 114 | + books = pd.read_csv('books.csv') |
| 115 | + selected_book = books[books['book_id'] == random_book_id][['title']] |
| 116 | + print("Selected Book:") |
| 117 | + print(selected_book) |
| 118 | + else: |
| 119 | + print("No books were found associated with the selected tag.") |
| 120 | + else: |
| 121 | + print("Invalid tag. Please select a valid tag.")''' |
| 122 | + |
| 123 | +selected_tag = input("Please select a tag: ").strip() # Strip whitespace from the input |
| 124 | +print("Selected tag:", selected_tag) |
| 125 | + |
| 126 | +if not selected_tag: |
| 127 | + print("No tag selected. Please enter a tag.") |
| 128 | +else: |
| 129 | + selected_tag_lower = selected_tag.lower() # Convert selected tag to lowercase |
| 130 | + top_tag_names_lower = top_tag_names.str.lower() # Convert top tag names to lowercase for comparison |
| 131 | + if selected_tag_lower not in top_tag_names_lower.values: |
| 132 | + print("Invalid label. Please select a tag from the top 10 most used tags.") |
| 133 | + else: |
| 134 | + selected_tag_id_series = tags[tags['tag_name'].str.lower() == selected_tag_lower]['tag_id'] |
| 135 | + if not selected_tag_id_series.empty: |
| 136 | + selected_tag_id = selected_tag_id_series.values[0] |
| 137 | + filtered_books = book_tags[book_tags['tag_id'] == selected_tag_id] |
| 138 | + if not filtered_books.empty: |
| 139 | + random_book_id = filtered_books.sample(1)['goodreads_book_id'].values[0] |
| 140 | + books = pd.read_csv('books.csv') |
| 141 | + selected_book = books[books['book_id'] == random_book_id][['title']] |
| 142 | + print("Selected Book:") |
| 143 | + print(selected_book) |
| 144 | + else: |
| 145 | + print("No books were found associated with the selected tag.") |
| 146 | + else: |
| 147 | + print("Invalid tag. Please select a valid tag.") |
| 148 | + |
0 commit comments