0

I'm trying to do a type check with an element of a pandas dataframe which appears to be a string:

type(atmdf.ix[row]['bid'])

<type 'str'>

however, if I do a type check I get False:

type(atmdf.ix[row]['bid']) is 'str'

False

even with the isinstance I get the same unexpected result:

isinstance(type(atmdf.ix[row]['bid']), str)

False

where am I wrong?

P.S. the content of the dataframe is something like this:

atmdf.ix[row]['bid']
'28.5'

thank you!

1
  • 2
    Your second one is incorrect should be type(atmdf.ix[row]['bid']) is str Commented Oct 16, 2014 at 11:02

1 Answer 1

2

You have to test the string itself with isintance, not the type:

In [2]: isinstance('string', str)
Out[2]: True

So in your case (leaving out the type(..)): isinstance(atmdf.ix[row]['bid'], str).

Your first check did not work because you have to compare to str (the type) not 'str' (a string).

Sign up to request clarification or add additional context in comments.

3 Comments

See comment of @EdChum: you have to compare to str not 'str'
@mspadaccino because you are comparing to a string 'str' rather than the type str
@mspadaccino : The type() function returns a type object, not a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.