Runner Bean Runner Bean - 10 months ago 95
Python Question

python pandas - check if a string type exists in a column

I know how to check for a 'nan' value in in column 'A' of dataframe 'df' as follows


but how can I check for a 'string', and I mean any string, since i do not know what the string text is, and then also to know which row it was found in?

Answer Source

If you are using Python 3, you can use a list comprehension and numpy.any

 import numpy as np

 np.any([isinstance(val, str) for val in df['A']])

If you are using Python 2, * belive that you need to replace str with basestring.