Python NumPy Mini Projects: Movie Ratings Analyzer

              It is a beginner friendly mini project in NumPy mini Project. It reads the user reviews. Analyzes the reviews and make a good statistical reports.

Let us implement this as follows…

Implementation:

  • This implementation starts from including numpy object.
  • The movies names are assigned for an array.
  • Ratings are recorder in another array.
  • 4 parameters are calculated here. first, average of the reviews. It uses mean() function.
  • Next, maximum and minimum calculation.This uses max() and min() functions.
  • Finally, median rating is calculated by median().
  • These values are displayed.
  • At last, the datas are sorted and displayed.

Code:

import numpy as np1

# Movie names

movies = np1.array([

    "Avengers:Doomsday",

    "Spider-Man: Brand New Day",

    "Jailer2",

    "Titanic",

    "Inception"

])

# Ratings out of 10

ratings = np1.array([8.6, 9.0, 9.3, 8.0, 8.1])

print("Movie Ratings")

for movie, rating in zip(movies, ratings):

    print(f"{movie}: {rating}")

# Statistics of the movie data

average_rating = np1.mean(ratings)

highest_rating = np1.max(ratings)

lowest_rating = np1.min(ratings)

median_rating = np1.median(ratings)

print("\n--- Statistics ---")

print("Average Rating:", average_rating)

print("Highest Rating:", highest_rating)

print("Lowest Rating:", lowest_rating)

print("Median Rating:", median_rating)

# Movies above average data

print("\nMovies Above Average Rating:")

above_avg = movies[ratings > average_rating]

for movie in above_avg:

    print(movie)

# Sorting of ratings

sorted_indices = np1.argsort(ratings)[::-1]

print("\nMovies Ranked:")

for i in sorted_indices:

    print(movies[i], "-", ratings[i])

Output:

Movie Ratings

Avengers:Doomsday: 8.6

Spider-Man: Brand New Day: 9.0

Jailer2: 9.3

Titanic: 8.0

Inception: 8.1

--- Statistics ---

Average Rating: 8.600000000000001

Highest Rating: 9.3

Lowest Rating: 8.0

Median Rating: 8.6

Movies Above Average Rating:

Spider-Man: Brand New Day

Jailer2

Movies Ranked:

Jailer2 - 9.3

Spider-Man: Brand New Day - 9.0

Avengers:Doomsday - 8.6

Inception - 8.1

Titanic - 8.0

The output is successful.

This is the way of implementing Movie Ratings Analyzer in Python using NumPy. Hope, you understood the concept. Keep Coding!!!!

Comments

Popular posts from this blog

How to create a XML DTD for displaying student details

Employee record management in C

Datatypes and Variables in java script