TMDb、tmdbv3api:按类型查找电影总数

问题描述 投票:0回答:1

我正在使用 tmdbv3api 包通过 TMDb API 提取电影信息。如何编写一个脚本,在其中指定类型类型(戏剧、恐怖、动作等),并且脚本返回属于该类型的所有电影的计数?

python
1个回答
-1
投票

当时没有任何关于数据结构的指示,这是一个有两种可能性的MWE:一种如果数据是 panda df,一种如果它是数组。数据也可以来自 csv/Excel 文件,您可以使用 pandas 加载它。

import pandas as pd
import numpy as np

type_to_look = "SF"

my_data = pd.DataFrame([["James Bond","Spy"], ["Avatar","SF"], ["Dune","SF"]],columns=["Movie","Style"])
number = len(my_data[my_data["Style"]==type_to_look].index)
print(f"With df : number of {type_to_look} movies : {number}")



my_array = np.array([["James Bond","Spy"], ["Avatar","SF"], ["Dune","SF"]])
number2 = (my_array[:,1] == type_to_look).sum()
print(f"With array : number of {type_to_look} movies : {number2}")
© www.soinside.com 2019 - 2024. All rights reserved.