Check if string is in a pandas dataframe

前端 未结 7 2040
北荒
北荒 2020-11-28 06:38

I would like to see if a particular string exists in a particular column within my dataframe.

I\'m getting the error

ValueError: The truth v

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 07:11

    If there is any chance that you will need to search for empty strings,

        a['Names'].str.contains('') 
    

    will NOT work, as it will always return True.

    Instead, use

        if '' in a["Names"].values
    

    to accurately reflect whether or not a string is in a Series, including the edge case of searching for an empty string.

提交回复
热议问题