Runner Bean Runner Bean - 1 year ago 183
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download