【发布时间】:2020-04-14 02:11:47
【问题描述】:
这是我的字典示例:
{'Fiction Books 2019': ['The Testaments by Margaret Atwood',
'Normal People by Sally Rooney',
'Where the Forest Meets the Stars by Glendy Vanderah',
'Ask Again, Yes by Mary Beth Keane',
'Queenie by Candice Carty-Williams',
"On Earth We're Briefly Gorgeous by Ocean Vuong",
'A Woman Is No Man by Etaf Rum',
'The Overdue Life of Amy Byler by Kelly Harms'... etc }
如何只保留书名?
我尝试了以下方法,但循环将所有书籍添加到字典中的每个键中:
books_name_dict = dict.fromkeys((col_names), [])
for k in books_name_dict:
for i in range(len(nominee_list_dict_try[k])):
books_name_dict[k].append(nominee_list_dict_try[k][i].split(' by ')[0])
【问题讨论】:
-
df['Fiction Books 2019'].str.split(" by ").str[0]?
标签: python dictionary data-science data-analysis