9 Sample
Notebook 9 - Sample Program¶
Make a copy of this notebook by selecting File->Save a copy in Drive from the menu bar above.
In this lesson, we're going to examine a simple Python program. The job of this app is to load some data from the Internet Movie Database (IMDB) and find the highest rated film.
The data used in this sample program comes from this Kaggle datsaset.
Things you'll learn in this lesson:
- become famliar with a simple but real Python program
import kagglehub
# Download latest version
path = kagglehub.dataset_download(“payamamanat/imbd-dataset”)
print(“Path to dataset files:", path)
Path to dataset files: /kaggle/input/imbd-dataset
! ls /kaggle/input/imbd-dataset/IMBD.csv
/kaggle/input/imbd-dataset/IMBD.csv
import csv
filename = "/kaggle/input/imbd-dataset/IMBD.csv”
top_rated = None
top_rating = -1
def check_if_new_leader(title, rating):
”""
store a new highest rated film and it’s corresponding rating
“”"
global top_rated
global top_rating
if rating > top_rating:
top_rated = title
top_rating = rating
with open(filename, “r”) as file:
count = 0
display_limit = 10
for f in csv.reader(file):
current_title = f[0]
if current_title == “title”:
continue
try:
current_rating = float(f[5])
except:
continue
check_if_new_leader(current_title, current_rating)
count += 1 # increment
print(f“Top rated of {count} films is {top_rated}/{top_rating}")
Top rated of 8784 films is BoJack Horseman/9.9