Skip to content

Instantly share code, notes, and snippets.

@TheBubblePopped
Created September 18, 2018 13:19
Show Gist options
  • Save TheBubblePopped/e90201d9de797da250fca856afeb93b1 to your computer and use it in GitHub Desktop.
Save TheBubblePopped/e90201d9de797da250fca856afeb93b1 to your computer and use it in GitHub Desktop.
justtoShow
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