我将 IMDbPY 与公开可用的 IMDb 数据集 ( https://www.imdb.com/interfaces/ ) 结合使用来创建自定义数据集pandas
。公共数据集包含很多重要信息,但据我所知,不包含绘图信息。IMDbPY 确实包含情节摘要,此外还包含情节提要和情节关键字,以情节、概要和电影类/字典的关键字键的形式出现。
我可以通过调用 API 来获取各个键的图:ia.get_movie(movie_index[2:])['plot'][0]
我使用 [2:] 因为索引的前 2 个字符在公共数据集中是“tt”,而 [0] 因为有很多图摘要所以我是从 IMDbPY 获取第一个。
但是,要获得 10,000 个绘图摘要,我需要进行 10,000 个 API 调用,这将花费我 7.5 小时,假设每个 API 调用需要 2.7 秒(这是我发现使用的tqdm
)。所以解决这个问题的方法是让它在一夜之间运行。还有其他解决方案吗?此外,有没有比我目前用键作为电影索引(例如“肖申克救赎”的 tt0111161)和值作为图然后将该字典转换为数据框的字典更好的方法呢?任何见解都值得赞赏。我的代码如下:
movie_dict = {}
for movie_index in tqdm(movies_index[0:10]):
#movie = ia.get_movie(movie_index[2:])
try:
movie_dict[movie_index] = ia.get_movie(movie_index[2:])['plot'][0]
except:
movie_dict[movie_index] = ''
plots = pd.DataFrame.from_dict(movie_dict, orient='index')
plots.rename(columns={0:'plot'}, inplace=True)
plots
plot
tt0111161 Two imprisoned men bond over a number of years...
tt0468569 When the menace known as the Joker emerges fro...
tt1375666 A thief who steals corporate secrets through t...
tt0137523 An insomniac office worker and a devil-may-car...
tt0110912 The lives of two mob hitmen, a boxer, a gangst...
tt0109830 The presidencies of Kennedy and Johnson, the e...
tt0120737 A meek Hobbit from the Shire and eight compani...
tt0133093 A computer hacker learns from mysterious rebel...
tt0167260 Gandalf and Aragorn lead the World of Men agai...
tt0068646 The aging patriarch of an organized crime dyna...