【发布时间】:2020-04-04 10:20:31
【问题描述】:
数据有 2 列,分别为 title 和 genre。所以我试图给与用户输入流派匹配的行的title 值。
这是我的尝试:
#CSV READ & GENRE-TITLE
data = pd.read_csv("data.csv")
df_title = data["title"]
df_genre = data["genre"]
#TOKENIZE
tokenized_genre = [word_tokenize(i) for i in df_genre]
tokenized_title = [word_tokenize(i) for i in df_title]
#INPUT-DATA MATCH
search = {e.lower() for l in tokenized_genre for e in l}
choice = input('Please enter a word = ')
while choice != "exit":
if choice.lower() in search:
print(data.loc[data.genre == {choice}, 'title'])
else:
print("The movie of the genre doesn't exist")
choice = input("Please enter a word = ")
但结果是:Series([], Name: title, dtype: object)
我该如何解决?
编辑: 标题的数据样本
0 The Story of the Kelly Gang
1 Den sorte drøm
2 Cleopatra
3 L'Inferno
4 From the Manger to the Cross; or, Jesus of
...
对于流派:
0 Biography, Crime, Drama
1 Drama
2 Drama, History
3 Adventure, Drama, Fantasy
4 Biography, Drama
...
【问题讨论】:
-
您能否提供儿子的样本数据,以便我们为您提供准确的帮助?我想你可以在这里只保留一个DataFrame。
-
@s.k 感谢提醒,编辑帖子并添加示例。