Check if a string in a Pandas DataFrame column is in a list of strings

后端 未结 4 1715
夕颜
夕颜 2020-11-27 14:59

If I have a frame like this

frame = pd.DataFrame({\'a\' : [\'the cat is blue\', \'the sky is green\', \'the dog is black\']})

and I want to

4条回答
  •  悲哀的现实
    2020-11-27 15:25

    For list should work

    print frame[frame['a'].isin(mylist)]     
    

    http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.isin.html

提交回复
热议问题