Created
September 18, 2018 13:19
-
-
Save TheBubblePopped/e90201d9de797da250fca856afeb93b1 to your computer and use it in GitHub Desktop.
justtoShow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
import pandas as pd | |
pd.set_option('display.max_columns', 50) | |
pd.set_option('display.width', 1000) | |
import pymongo | |
import time | |
movie = pd.read_csv('Pandas-Cookbook/data/movie.csv', index_col='movie_title') | |
"""Sick function that lets you filter and return movie with specific characteristics | |
sc = imbd score | |
cr = content rating | |
ty = titleyear | |
""" | |
def imdb_criteria(*criteria): | |
lastManStanding = [] | |
finalframe = pd.DataFrame() | |
amount_of_crit = len(criteria) | |
assert amount_of_crit > 0 | |
for c in criteria: | |
if c.startswith('sc'): | |
lastManStanding.append(movie.imdb_score > int(c[3:])) | |
# inputs https://en.wikipedia.org/wiki/Motion_Picture_Association_of_America_film_rating_system for sc | |
# General inputs G for General Audiences, PG for parental Guidance suggested, PG-13 for parents strongly | |
# cautioned, R for restircted, NC-17 for aadults only | |
elif c.startswith('cr='): | |
lastManStanding.append(movie.content_rating == str(c[3:])) | |
#titleyear inputs can be >, < , = and then well u find the movie for that specific attribute | |
elif c.startswith('ty'): | |
if c[2] == '>': | |
lastManStanding.append(movie.title_year > int(c[3:])) | |
elif c[2] == '<': | |
lastManStanding.append(movie.title_year < int(c[3:])) | |
elif c[2] == '=': | |
lastManStanding.append(movie.title_year == int(c[3:])) | |
else: | |
raise Exception("wtf that symbol") | |
# Final destination loop to cleanup the mess and find the result | |
for i in range(0, len(lastManStanding)): | |
lastManStanding[0] = lastManStanding[0] & lastManStanding[i] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment