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)]
添加回答
舉報