Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following is the assignment to be coded by using Python 3: Below is a link t

ID: 3861656 • Letter: T

Question

The following is the assignment to be coded by using Python 3:

Below is a link to the .csv files separated by title. Please ensure that these files remain exactly as isand are placed in the same directory as the .py file. Thank you.

http://pastebin.com/1ryLmfYu

Problem 1. Top Movies and Actors This problem is about analyzing data fromIMDB sts with top rated and top grossing movies. There are these files linked from the Homework 4 Canvas page: imdb-top-rated csv, listing the ranking of the top rated 250 movies. It has this format: Rank,Title, Year, IMDB Rating imdb-top-grossing.csv, listing the ranking of the highest grossing 250 movies. It has this format: Rank, Title, Year,USA Box Office imdb-top-casts.csv, listing the director and cast for the movies in the above files. It has this format: Title, Director, Actor 1, Actor 2, Actor 3, Actor 4, Actor 5. The actors are listed in billing order. This file does not have a heading These files are from Duke U. and seem to date from 2014.

Explanation / Answer

# Python code for displaying top 5 directors of top rated films and 5 directors of top grossing movies

import csv
rank_list=[]
director_list=[]
with open('imdb-top-rated.csv', 'rb') as csvfile: #opening csv file
   spamreader = csv.reader(csvfile, delimiter=',', quotechar='|') # reading csv file
   count=0
  
   for row in spamreader: # traversing each row in csv file
   #print ', '.join(row)
   tr=0
   rank=0
   title=""
   for r in row: #vising each item in each row
       if tr==0:
           rank=r
       if tr==1: # retrieving title from top-rated csv file for comparison
           title=r
           #print title
       tr+=1
   with open('imdb-top-casts.csv','rb') as director: # opening top-casts file
       line=csv.reader(director,delimiter=',',quotechar='|')
       for row1 in line :
           tc=0
           flag=0
           for t in row1 :
               if tc==0:
                   if title==t: #comparing tile from top-rated list with this title in top-casts file
                       flag=1
               if tc==2 and flag==1:
                   #print rank,t
                   rank_list.append(rank) # appending rank
                   director_list.append(t) # appending director name into list
               tc+=1
           #print "1 "
   if count==6:
       break
   count+=1

print "List of top five directors rank in descending order with the most movies in top rated list : "
i=4

# displaying director name and rank in descending order
while(i>=0):
   print rank_list[i],director_list[i]
   i=i-1

# Similar to above code for top grossing directors.

rank_list=[]
director_list=[]
with open('imdb-top-grossing.csv', 'rb') as csvfile:
   spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
   count=0
  
   for row in spamreader:
   #print ', '.join(row)
   tr=0
   rank=0
   title=""
   for r in row:
       if tr==0:
           rank=r
       if tr==1:
           title=r
           #print title
       tr+=1
   with open('imdb-top-casts.csv','rb') as director:
       line=csv.reader(director,delimiter=',',quotechar='|')
       for row1 in line :
           tc=0
           flag=0
           for t in row1 :
               if tc==0:
                   if title==t:
                       flag=1
               if tc==2 and flag==1:
                   #print rank,t
                   rank_list.append(rank)
                   director_list.append(t)
               tc+=1
           #print "1 "
   if count==6:
       break
   count+=1

print "List of top five directors rank in descending order with the most movies in top grossing list : "
i=4
while(i>=0):
   print rank_list[i],director_list[i]
   i=i-1

#output :

~G580$:python movie.py
List of top five directors rank in descending order with the most movies in top rated list :

5 1966
4 Quentin Tarantino
3 Francis Ford Coppola
2 Francis Ford Coppola
1 Frank Darabont
List of top five directors rank in descending order with the most movies in top grossing list :

5 George Lucas
4 Christopher Nolan
3 Joss Whedon
2 James Cameron
1 James Cameron