1 回答

TA貢獻1878條經驗 獲得超4個贊
您正在尋找在一系列列表中搜索字符串。一種方法是:
# Drop NaN rows
df = df.dropna(subset=["sentence_split"])
應用僅保留您要查找的列表中的元素的函數
# Apply this lamda function
df["sentence_split"] = df["sentence_split"].apply(lambda x: [i for i in x if "world" in i])
id sentence sentence_split
0 1 hello world \n my world [hello world , my world]
1 2 world is a great place \n we live in it [world is a great place ]
2 3 planet earth []
4 5 \n save the water []
5 6 []
添加回答
舉報