Skip to content

Commit 15a1060

Browse files
committed
resolved conflicts
2 parents 9fd34de + 5021a6c commit 15a1060

3 files changed

Lines changed: 5092 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import csv
2+
from collections import defaultdict, namedtuple, Counter
3+
4+
movies_csv = 'movie_metadata.csv'
5+
6+
7+
def get_movies_by_director(data=movies_csv):
8+
Movie = namedtuple('Movie', 'title year score')
9+
directors = defaultdict(list)
10+
with open(data, encoding='utf-8') as csvfile:
11+
reader = csv.DictReader(csvfile)
12+
for row in reader:
13+
try:
14+
director = row['director_name']
15+
movie = row['movie_title'].replace('\xa0', '')
16+
year = int(row['title_year'])
17+
score = float(row['imdb_score'])
18+
m = Movie(title=movie, year=year, score=score)
19+
directors[director].append(m)
20+
except ValueError:
21+
continue
22+
return directors
23+
24+
25+
def get_most_movies(count):
26+
directors = get_movies_by_director()
27+
cnt = Counter()
28+
for director, movies in directors.items():
29+
cnt[director] += len(movies)
30+
return cnt.most_common(count)
31+
32+
33+
if __name__ == '__main__':
34+
print(get_most_movies(5))

0 commit comments

Comments
 (0)