1 回答
TA贡献1824条经验 获得超8个赞
IIUC,我认为你可以使用这个:
原始df:
+----+-----------+--------------+----------------------------+
| | some_int | some_string | List_of_strings |
+----+-----------+--------------+----------------------------+
| 0 | 84 | something | [‘cat’,’dog’,’corndog’] |
| 1 | 74 | etc | [‘qwetry’,’celphone’] |
| 2 | 64 | etc | [‘dog’,corndog’] |
| 3 | 89 | etc | [‘etc’,’catfish’,’purple’] |
+----+-----------+--------------+----------------------------+
df[df['List_of_strings'].str.contains('corndog')]
输出:
some_int some_string List_of_strings
0 84 something [‘cat’,’dog’,’corndog’]
2 64 etc [‘dog’,corndog’]
编辑 考虑到列值是列表类型而不是字符串,您可以使用以下内容:
df[df['List_of_strings'].apply(lambda x: 'corndog' in x)]
添加回答
举报
