Checking if a data series is strings

后端 未结 2 883
無奈伤痛
無奈伤痛 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条回答
  •  误落风尘
    2020-12-06 14:35

    You can use this to see if all elements in a column are strings

    df.applymap(type).eq(str).all()
    
    a    False
    b     True
    c    False
    dtype: bool
    

    To just check if any are strings

    df.applymap(type).eq(str).any()
    

提交回复
热议问题