<jupyter_start><jupyter_text>Popular BooksTo be a popular book a book should have more than mean ratings<jupyter_code>df_moreThanMeanRatings = df[df["num_ratings"] > df.num_ratings.mean()]
df_moreThanMeanRatings.sort_values(by="avg_rating", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="avg_rating", y="title", data=df_moreThanMeanRatings.head(10), palette="Blues_d")
df_moreThanMeanRatings.head(10)[["title","num_ratings","avg_rating","num_reviews"]]
df_moreThanMeanRatings.sort_values(by="num_ratings", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="num_ratings", y="title", data=df_moreThanMeanRatings.head(10), palette="Blues_d")
df_moreThanMeanRatings.head(10)[["title","num_ratings","num_reviews","avg_rating"]]
df_moreThanMeanRatings.sort_values(by="num_reviews", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="num_reviews", y="title", data=df_moreThanMeanRatings.head(10), palette="Blues_d")
df_moreThanMeanRatings.head(10)[["title","num_reviews","num_ratings","avg_rating"]]<jupyter_output>C:\Users\<NAME>\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """Entry point for launching an IPython kernel.<jupyter_text>Popular authors<jupyter_code>authors = df_moreThanMeanRatings.author.drop_duplicates()
df_authors ={}
for author in authors:
    df_authors[author] = df_moreThanMeanRatings[df_moreThanMeanRatings["author"] == author]
avg_author_rating = []
num_author_reviews = []
num_author_ratings = []
num_books = []

for author in authors:
    avg_author_rating.append(df_authors[author].avg_rating.mean())
    num_author_reviews.append(df_authors[author].num_reviews.sum())
    num_author_ratings.append(df_authors[author].num_ratings.sum())
    num_books.append(df_authors[author].title.count())

author_rating = {'author': authors, 'average_rating': avg_author_rating, 'num_reviews': num_author_reviews, 'num_ratings': num_author_ratings, "num_books": num_books}
author_rating = pd.DataFrame.from_dict(author_rating)
author_rating.sort_values(by="num_reviews", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="num_reviews", y="author", data=author_rating.head(10), palette="Blues_d")
author_rating.head(10)
author_rating.sort_values(by="num_ratings", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="num_ratings", y="author", data=author_rating.head(10), palette="Blues_d")
author_rating.head(10)<jupyter_output><empty_output><jupyter_text>author_rating.sort_values(by="average_rating", inplace=True, ascending=False)fig, ax = plt.subplots(figsize=(7,7))sns.barplot(x="average_rating", y="author", data=author_rating.head(10), palette="Blues_d")author_rating.head(10) Scatter plot num_ratings vs average_rating  Popular Genres<jupyter_code>genres = ['Fiction',
       'Contemporary', 'Romance', 'Mystery', 'Young Adult', 'Fantasy',
       'Audiobook', 'Thriller', 'Adult', 'Historical', 'Historical Fiction',
       'Nonfiction', 'Mystery Thriller', 'Contemporary Romance', 'Suspense',
       'Adult Fiction', 'Science Fiction', 'Crime', 'Womens Fiction', 'LGBT',
       'Chick Lit', 'Cultural', 'Autobiography', 'Paranormal', 'Memoir',
       'Literary Fiction', 'New Adult', 'War', 'Biography', 'Magic']
df_genres ={}
for genre in genres:
    df_genres[genre] = df[df[genre] == 1]
print(df_genres['Fiction'].shape[0])
print(df_genres['Fiction'].count())
avg_genre_rating = []
num_genre_reviews = []
num_genre_ratings = []
num_books_genre = []

for genre in genres:
    avg_genre_rating.append(df_genres[genre].avg_rating.mean())
    num_genre_reviews.append(df_genres[genre].num_reviews.sum())
    num_genre_ratings.append(df_genres[genre].num_ratings.sum())
    num_books_genre.append(df_genres[genre].shape[0])
genre_rating = {'genre': genres, 'average_rating': avg_genre_rating, 'num_reviews': num_genre_reviews, 'num_ratings': num_genre_ratings, 'num_books': num_books_genre}
genre_rating = pd.DataFrame.from_dict(genre_rating)
genre_rating['num_reviews_norm'] = genre_rating['num_reviews'] / genre_rating['num_books']
genre_rating['num_ratings_norm'] = genre_rating['num_ratings'] / genre_rating['num_books']
genre_rating.sort_values(by="num_reviews_norm", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="num_reviews_norm", y="genre", data=genre_rating.head(10), palette="Blues_d")
genre_rating.head(10)<jupyter_output><empty_output><jupyter_text>normalised for number of books<jupyter_code>genre_rating.sort_values(by="num_ratings_norm", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="num_ratings_norm", y="genre", data=genre_rating.head(10),palette="Blues_d")
genre_rating.head(10)
genre_rating.sort_values(by="average_rating", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="average_rating", y="genre", data=genre_rating.head(10), palette="Blues_d")
genre_rating.head(10)<jupyter_output><empty_output><jupyter_text>Hottest books* Popularity of books during corona in relationship to their age* Ratings and reviews per day<jupyter_code>df["num_reviews_normalized"] = df["num_reviews"] / df["age"]
df["num_ratings_normalized"] = df["num_ratings"] / df["age"]
df.head()<jupyter_output><empty_output><jupyter_text>Hot books should have at least more than the average amount of reviews<jupyter_code>df_moreThanMeanRatings_normalized = df[df["num_ratings_normalized"] > df.num_ratings_normalized.mean()]
df_moreThanMeanRatings_normalized.sort_values(by="avg_rating", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="avg_rating", y="title", data=df_moreThanMeanRatings_normalized.head(10), palette="Blues_d")
df_moreThanMeanRatings_normalized.head(10)[["title","num_ratings_normalized","avg_rating","num_reviews_normalized"]]
df_moreThanMeanRatings_normalized.sort_values(by="num_ratings_normalized", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="num_ratings_normalized", y="title", data=df_moreThanMeanRatings_normalized.head(10), palette="Blues_d")
df_moreThanMeanRatings_normalized.head(10)[["title","num_ratings_normalized","avg_rating","num_reviews_normalized","age"]]
df_moreThanMeanRatings_normalized.sort_values(by="num_reviews_normalized", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="num_reviews_normalized", y="title", data=df_moreThanMeanRatings_normalized.head(10), palette="Blues_d")
df_moreThanMeanRatings_normalized.head(10)[["title","num_ratings_normalized","avg_rating","num_reviews_normalized","age"]]<jupyter_output>C:\Users\<NAME>\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """Entry point for launching an IPython kernel.<jupyter_text>Single value hotness score$$hotness = (\frac{reviews/day_{book}}{reviews/day_{ensemble-average}} + \frac{ratings/day_{book}}{ratings/day_{ensemble-average}})\times \frac{rating_{book}}{rating_{ensemble-average}}$$<jupyter_code>df_moreThanMeanRatings_normalized.loc[:,['age', 'fraction_review_hot']]

sns.distplot(df_moreThanMeanRatings_normalized.num_reviews_normalized)
df_moreThanMeanRatings_normalized["fraction_review_hot"] = (df_moreThanMeanRatings_normalized["num_reviews_normalized"]/df_moreThanMeanRatings_normalized.num_reviews_normalized.median())
df_moreThanMeanRatings_normalized["hotness"] = (((df_moreThanMeanRatings_normalized["num_reviews_normalized"]/df_moreThanMeanRatings_normalized.num_reviews_normalized.median()) 
                                                 + (df_moreThanMeanRatings_normalized["num_ratings_normalized"]/df_moreThanMeanRatings_normalized.num_ratings_normalized.median())) 
                                                * df_moreThanMeanRatings_normalized["avg_rating"] / df_moreThanMeanRatings_normalized.avg_rating.median() )
df_moreThanMeanRatings_normalized.sort_values(by="hotness", inplace=True, ascending=False)
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="hotness", y="title", data=df_moreThanMeanRatings_normalized.head(10), palette="Blues_d")
df_moreThanMeanRatings_normalized.head(10)[["title","hotness","num_ratings_normalized","avg_rating","num_reviews_normalized","age"]]
fig, ax = plt.subplots(figsize=(7,7))
sns.barplot(x="num_reviews", y="title", data=df_moreThanMeanRatings.head(10), palette="Blues_d")
df_moreThanMeanRatings.head(10)[["title","num_reviews","num_ratings","avg_rating"]]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1473613595706619, 'fraction_numerical': 0.010174418604651164, 'mean_word_length': 9.648809523809524, 'pattern_counts': {'":': 1, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '409520', 'license': 'MIT', 'n_tokens_mistral': 3405, 'n_tokens_neox': 3214, 'n_words': 401, 'path': 'data_analysis_hannes.ipynb', 'repo_name': 'mastrero/TechLab-group15', 'size': '8958'}