Get Metacritic Ratings

Using Metacritic API


In [1]:
%matplotlib inline

import configparser
import os

import requests
from tqdm import tqdm
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import sparse, stats, spatial
import scipy.sparse.linalg
from sklearn import preprocessing, decomposition
import librosa
import IPython.display as ipd
import json

#added by me:
import requests

Load Dataset


In [2]:
all_movies = pd.read_csv('Saved_Datasets/CleanDataset.csv')

In [3]:
all_movies.head()


Out[3]:
id budget genres imdb_id overview production_companies release_date revenue tagline title actor1_name actor2_name actor3_name actor4_name actor5_name director_name
0 12 94000000 Animation|Family 266543 Nemo, an adventurous young clownfish, is unexp... Pixar Animation Studios 2003-05-30 940335536 There are 3.7 trillion fish in the ocean, they... Finding Nemo Albert Brooks Ellen DeGeneres Alexander Gould Willem Dafoe Brad Garrett Andrew Stanton
1 16 12800000 Drama|Crime|Music 168629 Selma, a Czech immigrant on the verge of blind... Fine Line Features 2000-05-17 40031879 You don't need eyes to see. Dancer in the Dark Björk Catherine Deneuve David Morse Peter Stormare Joel Grey Lars von Trier
2 22 140000000 Adventure|Fantasy|Action 325980 Jack Sparrow, a freewheeling 17th-century pira... Walt Disney Pictures 2003-09-07 655011224 Prepare to be blown out of the water. Pirates of the Caribbean: The Curse of the Bla... Johnny Depp Geoffrey Rush Orlando Bloom Keira Knightley Jack Davenport Gore Verbinski
3 24 30000000 Action|Crime 266697 An assassin is shot at the altar by her ruthle... Miramax Films 2003-10-10 180949000 Go for the kill. Kill Bill: Vol. 1 Uma Thurman Lucy Liu Vivica A. Fox Daryl Hannah David Carradine Quentin Tarantino
4 25 72000000 Drama|War 418763 Jarhead is a film about a US Marine Anthony Sw... Universal Pictures 2005-04-11 96889998 Welcome to the suck. Jarhead Jamie Foxx Scott MacDonald none Lucas Black Peter Sarsgaard Sam Mendes

Drop Unused Columns


In [4]:
all_movies.drop([  'budget', 'genres', 'id', 'overview','release_date', 'revenue', 'tagline', 'actor1_name', 'actor2_name',
                   'actor3_name', 'actor4_name', 'actor5_name', 'director_name', 'production_companies'] ,axis=1, inplace = True)

In [5]:
all_movies = all_movies.drop(all_movies[all_movies['imdb_id'].isnull()].index)

Metacritic API

Ratings based on several critics, weigthed average between them, best rating: 100


In [6]:
def find_rating(film_name):
    '''Return rating from Metacritic API from film name. Date optionnal'''
    
    #remove punctuation
    film_name = film_name.replace(":","")
    film_name = film_name.replace("?","")
    film_name = film_name.replace(".","")
    film_name = film_name.replace("&","")
    film_name = film_name.replace("$","-")
    film_name = film_name.replace("/","-")
    
    #film name must be at least 4 characters
    if len(film_name) < 4: film_name = film_name+"----"
    
    website = "https://api-marcalencc-metacritic-v1.p.mashape.com/search/"
    headers={
        "X-Mashape-Key": "xVCvaKLJ5UmshSg19R7nyselFT6rp19AZvkjsnqxyF1gZvoz5x",
        "Accept": "application/json"
    }
    
    try:
        response = requests.get(website+film_name+"/movie",headers=headers).json()
        return response[0]['SearchItems'][0]['Rating']['CriticRating']
    except:
        print("Error: '"+film_name+"'")
        return 'Error'

Example:


In [26]:
find_rating("Memento")


Out[26]:
80

Find Rating for each Movie


In [7]:
test = all_movies[:].copy()
#test = pd.read_csv('Saved_Datasets/metacritic_ratings.csv', encoding='cp1252')
#test = pd.read_csv('Saved_Datasets/rating_with_errors.csv', encoding='cp1252') # old one, unused

In [8]:
#Takes approx. 2-3 hours !!!
test['Metacritic'] = test.apply (lambda row: find_rating(row['title']),axis=1)


Error: 'Harry Potter and the Philosopher's Stone'
Error: 'Mulholland Drive'
Error: 'Mr Bean's Holiday'
Error: 'The Grudge 3'
Error: 'Fantastic 4 Rise of the Silver Surfer'
Error: 'Death Proof'
Error: 'The Tulse Luper Suitcases, Part 3 From Sark to the Finish'
Error: '310 to Yuma'
Error: 'Ken Park'
Error: 'Dude, Where’s My Car'
Error: 'What Just Happened'
Error: 'Cry_Wolf'
Error: 'D-Tox'
Error: 'The Death and Life of Bobby Z'
Error: 'WALL·E'
Error: 'Jeepers Creepers 2'
Error: 'National Lampoon’s Van Wilder'
Error: 'Harry Potter and the Deathly Hallows Part 1'
Error: 'Stargate The Ark of Truth'
Error: 'Kidulthood'
Error: 'The Lazarus Project'
Error: 'Justice League The New Frontier'
Error: 'Assembly'
Error: 'Dhoom 2'
Error: 'Virgin Territory'
Error: 'Romanzo criminale'
Error: 'Jaane Tu Ya Jaane Na'
Error: 'Foolproof'
Error: 'The Boy in the Striped Pyjamas'
Error: 'Dil Chahta Hai'
Error: 'Hood of Horror'
Error: 'Fishtales'
Error: 'Phoonk'
Error: 'The Best Two Years'
Error: 'The Car Keys'
Error: 'Kung Fu Dunk'
Error: 'Iron  Blood The Legend of Taras Bulba'
Error: 'Assassination of a High School President'
Error: 'Man-Thing'
Error: 'The Boat That Rocked'
Error: 'Shootout at Lokhandwala'
Error: 'Hardball'
Error: 'Navigating the Heart'
Error: 'A Four Letter Word'
Error: 'Loose Change Final Cut'
Error: 'It's Alive'
Error: 'Mary and Max'
Error: 'Xchange'
Error: 'Ghost Game'
Error: 'Baptists at Our Barbecue'
Error: 'Hachi A Dog's Tale'
Error: 'Universal Soldier Regeneration'
Error: 'Halo Legends'
Error: 'Hurricane Season'
Error: 'Setem'
Error: 'Nanny McPhee and the Big Bang'
Error: 'Monique'
Error: 'It's a Boy Girl Thing'
Error: 'To Rob a Thief'
Error: 'Cats  Dogs 2  The Revenge of Kitty Galore'
Error: 'Men in Black 3'
Error: 'Step Up 3D'
Error: 'Zyzzyx Road'
Error: 'Saw The Final Chapter'
Error: 'StreetDance 3D'
Error: 'TEKKEN'
Error: 'Hatchet II'
Error: 'Cruel World'
Error: '4321'
Error: 'Action Replayy'
Error: 'The Nutcracker The Untold Story'
Error: 'Zonad'
Error: '71 Into the Fire'
Error: 'Church Ball'
Error: 'Blitz'
Error: 'Baywatch The Reunion'
Error: 'Hollywood  Wine'
Error: 'The Powerpuff Girls Movie'
Error: 'Money No Enough 2'
Error: 'Pro Lyuboff'
Error: 'PickUp With no Rules'
Error: 'Aegan'
Error: 'Varalaru'
Error: 'Paramasivan'
Error: 'Jana'
Error: 'Anjaneya'
Error: 'Villan'
Error: 'Unnai Kodu Ennai Tharuven'
Error: 'Jai Surya'
Error: 'Setup'
Error: 'Belukar'
Error: 'The Pirates! In an Adventure with Scientists!'
Error: 'Trois'
Error: 'Sea Rex 3D Journey to a Prehistoric World'
Error: 'A Lonely Place to Die'
Error: 'A Few Best Men'
Error: 'L!fe Happens'
Error: 'Vizontele Tuuba'
Error: 'For Greater Glory - The True Story of Cristiada'
Error: 'Bikini Spring Break'
Error: 'Foodfight!'
Error: 'Behind the Candelabra'
Error: 'Voracious'
Error: 'Redd Inc'
Error: 'Hummingbird'
Error: 'Tiktik The Aswang Chronicles'
Error: 'Husbands in Goa'
Error: 'Empire State'
Error: 'Housos vs Authority'
Error: 'Alan Partridge Alpha Papa'
Error: 'Rigodon'
Error: 'Arrambam'
Error: 'Atlas Shrugged Part III Who is John Galt'
Error: 'Bharya Athra Pora'
Error: 'Savages Crossing'
Error: 'Justice League War'
Error: 'Mindscape'
Error: 'Chinthamani Kolacase'
Error: 'A Gambler's Story'
Error: 'House of Good and Evil'
Error: 'My Lady Boss'
Error: 'Boss Wants a Happy Ending'
Error: 'Wallander - The Secret'
Error: 'Thanks Maa'
Error: 'Mrs Brown's Boys D'Movie'
Error: 'Dubrovskiy'
Error: 'Googly'
Error: 'Parts Per Billion'
Error: 'Penguins of Madagascar Operation Antarctica'
Error: 'Scherzi il film'
Error: 'Comic 8'
Error: 'A Long Way Off'
Error: 'Mummy, I'm a Zombie'
Error: 'No more nights and no more days'
Error: 'Green Eyes'
Error: 'Bastille Day'
Error: 'The House at the Edge of the Galaxy'
Error: 'Ah Boys to Men 3 Frogmen'
Error: 'The Worst Movie Ever!'
Error: 'Long Long Time Ago'
Error: 'Sanam Re'
Error: 'Munafik'
Error: 'Birds of Passage'
Error: 'Sinistre'
Error: 'The Perfect Weapon'
Error: 'Last Day With Lizzy'
Error: 'A Family On Edge'
Error: 'D'Unbelievables One Hell of a Do'
Error: 'Browncoats Redemption'
Error: 'Thoughtless'

Apply function to Errors only


In [86]:
#Takes approx. 15-30 min. !!!
test['Metacritic'] = test.loc[test['Metacritic']=='Error'].apply (lambda row: find_rating(row['title']),axis=1)


Error: 'Harry Potter and the Philosopher's Stone'
Error: 'Mulholland Drive'
Error: 'Mr Bean's Holiday'
Error: 'The Grudge 3'
Error: 'Fantastic 4 Rise of the Silver Surfer'
Error: 'Death Proof'
Error: 'Hallam Foe'
Error: 'Yo tengo un corazón que quiere hundir mi cuerpo en los mares de ilusión'
Error: 'The Tulse Luper Suitcases, Part 1 The Moab Story'
Error: 'The Tulse Luper Suitcases, Part 2 Vaux to the Sea'
Error: 'The Tulse Luper Suitcases, Part 3 From Sark to the Finish'
Error: '310 to Yuma'
Error: 'Ken Park'
Error: 'Dude, Where’s My Car'
Error: 'What Just Happened'
Error: 'Cry_Wolf'
Error: 'D-Tox'
Error: 'The Death and Life of Bobby Z'
Error: 'Itty Bitty Titty Committee'
Error: 'WALL·E'
Error: 'Jeepers Creepers 2'
Error: 'National Lampoon’s Van Wilder'
Error: 'Harry Potter and the Deathly Hallows Part 1'
Error: 'Stargate The Ark of Truth'
Error: 'Kidulthood'
Error: 'The Lazarus Project'
Error: 'Justice League The New Frontier'
Error: 'Assembly'
Error: 'Dhoom 2'
Error: 'Dr Horrible's Sing-Along Blog'
Error: 'Virgin Territory'
Error: 'Romanzo criminale'
Error: 'Jaane Tu Ya Jaane Na'
Error: 'Foolproof'
Error: 'The Boy in the Striped Pyjamas'
Error: 'The Work and the Glory II American Zion'
Error: 'Dil Chahta Hai'
Error: 'Hood of Horror'
Error: 'Fat Pizza'
Error: 'Fishtales'
Error: 'Phoonk'
Error: 'The Best Two Years'
Error: 'The Car Keys'
Error: 'Kung Fu Dunk'
Error: 'Iron  Blood The Legend of Taras Bulba'
Error: 'Assassination of a High School President'
Error: 'Man-Thing'
Error: 'The Boat That Rocked'
Error: 'The Derby Stallion'
Error: 'Mangal Pandey - The Rising'
Error: 'Shootout at Lokhandwala'
Error: 'Hardball'
Error: 'Navigating the Heart'
Error: 'A Four Letter Word'
Error: 'Shabd'
Error: 'Loose Change Final Cut'
Error: 'It's Alive'
Error: 'Mozart and the Whale'
Error: 'Nieng Arp'
Error: 'Nasty Old People'
Error: 'Mary and Max'
Error: 'Main Aurr Mrs Khanna'
Error: 'Love and the City'
Error: 'The Decline And Fall Of America'
Error: 'Xchange'
Error: 'Ghost Game'
Error: 'October Moon'
Error: 'Baptists at Our Barbecue'
Error: 'Hachi A Dog's Tale'
Error: 'Universal Soldier Regeneration'
Error: 'Halo Legends'
Error: 'Rann'
Error: 'Hurricane Season'
Error: 'The Work and the Glory III A House Divided'
Error: 'Setem'
Error: 'Men with Brooms'
Error: 'The Errand of Angels'
Error: 'Nanny McPhee and the Big Bang'
Error: 'Monique'
Error: 'The Work and the Glory'
Error: 'It's a Boy Girl Thing'
Error: 'To Rob a Thief'
Error: 'Prince Vladimir'
Error: 'Cats  Dogs 2  The Revenge of Kitty Galore'
Error: 'Men in Black 3'
Error: 'Step Up 3D'
Error: 'Zyzzyx Road'
Error: 'Saw The Final Chapter'
Error: 'StreetDance 3D'
Error: 'Chasing Ghosts'
Error: 'TEKKEN'
Error: 'Dark Regrets'
Error: 'Like Dandelion Dust'
Error: 'Cruel World'
Error: '4321'
Error: 'Phone Police'
Error: 'Quiet City'
Error: 'Mother Teresa of Calcutta'
Error: 'Lynch Mob'
Error: 'Ann Rule Presents The Stranger Beside Me'
Error: 'Panchathantiram'
Error: 'Action Replayy'
Error: 'The Nutcracker The Untold Story'
Error: 'Zonad'
Error: 'The End of Poverty'
Error: '71 Into the Fire'
Error: 'Deadlands The Rising'
Error: 'Church Ball'
Error: 'Waltzing Anna'
Error: 'Blitz'
Error: 'The Graduates'
Error: 'Baywatch The Reunion'
Error: 'Hollywood  Wine'
Error: 'Deadlands 2 Trapped'
Error: 'The Powerpuff Girls Movie'
Error: 'Love, Sex, and Eating the Bones'
Error: 'Dream Well'
Error: 'Money No Enough 2'
Error: 'William  Kate'
Error: 'Pro Lyuboff'
Error: 'PickUp With no Rules'
Error: 'Stealing Sinatra'
Error: 'Aegan'
Error: 'Attagasam'
Error: 'Mugavari'
Error: 'Varalaru'
Error: 'Thirupathi'
Error: 'Paramasivan'
Error: 'Jana'
Error: 'Anjaneya'
Error: 'Villan'
Error: 'Unnai Kodu Ennai Tharuven'
Error: 'Manikanda'
Error: 'Aanai'
Error: 'Jai Surya'
Error: 'Parasuram'
Error: 'Sarvam'
Error: 'Cicakman'
Error: 'A Little Night Music'
Error: 'Setup'
Error: 'The Last Godfather'
Error: 'Belukar'
Error: 'The Pirates! In an Adventure with Scientists!'
Error: 'The House of Usher'
Error: 'Trois'
Error: 'Silk Shoes'
Error: 'Nurse 3-D'
Error: 'Sea Rex 3D Journey to a Prehistoric World'
Error: 'Ayumi Hamasaki Rock ’n' Roll Circus Tour Final 7 Days Special'
Error: 'Louis CK Live at the Beacon Theater'
Error: 'A Lonely Place to Die'
Error: 'A Few Best Men'
Error: 'L!fe Happens'
Error: 'Vizontele Tuuba'
Error: 'For Greater Glory - The True Story of Cristiada'
Error: 'Blowin' In The Wind'
Error: 'The 13th Alley'
Error: 'Hank Williams First Nation'
Error: 'Shikshanachya Aaicha Gho'
Error: 'Bikini Spring Break'
Error: 'Aquí Entre Nos'
Error: 'Foodfight!'
Error: 'Barbet  L'Homme de la situation'
Error: 'Behind the Candelabra'
Error: 'Voracious'
Error: 'Jatt  Juliet'
Error: 'The Story Of Short Stack'
Error: 'Suave Patria'
Error: 'Redd Inc'
Error: 'Hummingbird'
Error: 'Tiktik The Aswang Chronicles'
Error: 'Son of Sardaar'
Error: 'Greatest Hits'
Error: 'The Matriarch'
Error: 'Mrs Brown's Boys Live Tour Good Mourning Mrs Brown'
Error: 'Carmen G'
Error: 'Husbands in Goa'
Error: 'Empire State'
Error: 'The Cure 4 Tour at Madison Square Garden'
Error: 'The Cure - Curiosa Festival'
Error: 'Housos vs Authority'
Error: 'My Brother's War'
Error: 'Evidence Of A Haunting'
Error: 'Alan Partridge Alpha Papa'
Error: 'Rigodon'
Error: 'Tell 'em Steve-Dave Puppet Theatre'
Error: 'Arrambam'
Error: 'Ah Boys To Men (Part 2)'
Error: 'Komaram Puli'
Error: 'Atlas Shrugged Part III Who is John Galt'
Error: 'Treasures OK'
Error: 'Wanderlei Silva fighting for PRIDE'
Error: 'Legends The Five Greatest Fighters from Pride FC (Fedor Emelianenko)'
Error: 'Roaming Hungry'
Error: 'One Moment More'
Error: 'Bharya Athra Pora'
Error: 'Savages Crossing'
Error: 'Justice League War'
Error: 'Anonymous Celebrities Animatic'
Error: 'Mocca Life Keeps on Turning'
Error: 'Endank Soekamti Rock For Kamtis'
Error: 'Mindscape'
Error: 'Chinthamani Kolacase'
Error: 'A Gambler's Story'
Error: 'House of Good and Evil'
Error: 'Jessica Simpson - Reality Tour Live'
Error: 'My Lady Boss'
Error: 'Candy Thieves'
Error: 'Lesnaya tsarevna'
Error: 'Time of Her Life'
Error: 'Boss Wants a Happy Ending'
Error: 'Short Stack Live at the Sydney Opera House'
Error: 'Wallander - The Secret'
Error: 'Thanks Maa'
Error: 'Mrs Brown's Boys D'Movie'
Error: 'Dubrovskiy'
Error: 'D'Unbelievables D'Mother'
Error: 'Googly'
Error: 'Continuity Error'
Error: 'Parts Per Billion'
Error: 'Latham Entertainment Presents An All New Comedy Experience'
Error: 'Penguins of Madagascar Operation Antarctica'
Error: 'Scherzi il film'
Error: 'The Rance Allen Group Front Row Live'
Error: 'Freaky Night'
Error: 'Salem Abu Ukhtuh'
Error: 'Comic 8'
Error: 'Ho Ho Ho 2  A family lottery'
Error: 'Care Bears Season of Caring'
Error: 'Pig Tales Vol 3 Puffed Up Piglets  Time for A Change'
Error: 'Little Tikes Land'
Error: 'Garfield and Friends Dreams  Schemes'
Error: 'Pyaar Wali Love Story'
Error: 'A Long Way Off'
Error: 'Can You Imagine'
Error: 'Mummy, I'm a Zombie'
Error: 'Rock Sangkut'
Error: 'No more nights and no more days'
Error: 'Be Astonished'
Error: 'Anthony Daniels'
Error: 'Above  Beyond - ABGT100 - Live from Madison Square Garden'
Error: 'Green Eyes'
Error: 'Zid----'
Error: 'Def Comedy Jam Classics Volume Two'
Error: 'Jayne Middlemiss Love Yoga'
Error: 'The Adventures of Tim and Ben'
Error: 'Bastille Day'
Error: 'Savage High'
Error: 'The World Underground China'
Error: 'The House at the Edge of the Galaxy'
Error: 'Coulrophobia'
Error: 'Ah Boys to Men 3 Frogmen'
Error: 'Hawa Bodol'
Error: 'The Worst Movie Ever!'
Error: 'Sweet Journey'
Error: 'Head Full of Dreams, Heart Full of Promises'
Error: 'Medicinmannen'
Error: 'The Sabinal Canyon'
Error: 'Revenge An Short Film'
Error: 'Vipin and Rosh Wedding'
Error: 'Long Long Time Ago'
Error: 'Sanam Re'
Error: 'Munafik'
Error: 'Birds of Passage'
Error: 'Mr Wimmer's Fun House'
Error: 'The Nightmare at KFC'
Error: 'Ghosts of Shepherdstown'
Error: 'Blokes on Coke'
Error: 'Sinistre'
Error: 'Walking With Dinosaurs  Prehistoric Planet'
Error: 'Vaibhav Movie'
Error: 'Badshahi Angti'
Error: 'The Wife's Letter'
Error: 'Yellow Raincoat'
Error: 'Billy Yeager The Ineffable Enigma'
Error: 'Mars Pioneering the Planet'
Error: 'Room Zero'
Error: 'SWAG - Episode 2 The Texas Blues'
Error: 'The Perfect Weapon'
Error: 'Last Day With Lizzy'
Error: 'What Makes Me Tic'
Error: 'Life Under The Horseshoe'
Error: 'Jockstrap Slaughterhouse'
Error: 'Drain the Bermuda Triangle'
Error: 'SWAG - Episode 25 The Baby Eater'
Error: 'A Family On Edge'
Error: 'MJS----'
Error: 'Let's Eat'
Error: 'D'Unbelievables One Hell of a Do'
Error: 'Finn  the Sea of Noise'
Error: 'Peak Valley'
Error: 'The Morrison Project'
Error: 'Untitled Document'
Error: 'Celldweller Start of an Empire'
Error: 'HP1's Hijacked The Full Movie'
Error: 'Time Will Tell'
Error: 'HP1's The Studio'
Error: 'Untitled Satire'
Error: 'Requiem for a Tuesday'
Error: 'Cycle'
Error: 'Ultimate Mars Challenge'
Error: 'Living on Mars'
Error: 'Browncoats Redemption'
Error: 'Lines of Glory'
Error: 'Seeking Nirvana'
Error: 'Thoughtless'

Compute error


In [ ]:
test_fail = test.loc[test['Metacritic']=='Error']
print("Nb. errors: "+str(len(test_fail))+" ("+str(len(test_fail)/len(test)*100)[:4]+"%)")

! Save Dataset !


In [5]:
test.to_csv('Saved_Datasets/metacritic_ratings.csv', index=False)

Load Dataset


In [2]:
meta = pd.read_csv('Saved_Datasets/metacritic_ratings.csv')

In [ ]: