Python & Pandas: How to query if a list-type column contains something?

前端 未结 5 864
攒了一身酷
攒了一身酷 2020-11-27 17:59

I have a dataframe, which contains info about movies. It has a column called genre, which contains a list of genres it belongs to. For example:

         


        
5条回答
  •  悲哀的现实
    2020-11-27 18:31

    One liner using boolean indexing and list comprehension:

    searchTerm = 'something'
    df[[searchTerm in x for x in df['arrayColumn']]]
    

提交回复
热议问题