Checking if a data series is strings

后端 未结 2 884
無奈伤痛
無奈伤痛 2020-12-06 14:00

I want to check if a column in a dataframe contains strings. I would have thought this could be done just by checking dtype, but that isn\'t the case. A pandas series that c

2条回答
  •  旧时难觅i
    2020-12-06 14:55

    You could map the data with a function that converts all the elements to True or False if they are equal to str-type or not, then just check if the list contains any False elements

    The example below tests a list containing element other then str. It will tell you True if data of other type is present

    test = [1, 2, '3']
    False in map((lambda x: type(x) == str), test)
    

    Output: True

提交回复
热议问题