У меня есть фрейм данных "df1":
adj response
beautiful ["She's a beautiful girl/woman, and also a good teacher."]
good ["She's a beautiful girl/woman, and also a good teacher."]
hideous ["This city is hideous, let's move to the countryside."]
И вот список объектов:
object=["girl","teacher","city","countryside","woman"]
Код:
df1['response_split']=df1['response'].str.split(",")
После того, как я разделил его, фрейм данных будет выглядеть так:
adj response_split
beautiful ["She's a beautiful girl/woman", " and also a good teacher."]
good ["She's a beautiful girl/woman", " and also a good teacher."]
hideous ["This city is hideous", " let's move to the countryside."]
Я хочу добавить еще один столбец «response_object», если они находят в ответе adj, они находят его объект из списка: ожидаемый результат
adj response_split response_object
beautiful ["She's a beautiful girl/woman", " and also a good teacher."] girl
beautiful ["She's a beautiful girl/woman", " and also a good teacher."] woman
good ["She's a beautiful girl/woman", " and also a good teacher."] teacher
hideous ["This city is hideous", " let's move to the countryside."] city
код:
for i in df1['response_split']:
if df1['adj'] in i:
if any(x in i and x in object):
match = list(filter(lambda x: x in i, object))
df1['response_object']=match
Распечатывается Ошибка значения