python - Pandas error TypeError: data type not understood -
i've been trying slice pandas dataframe using boolean indexing code like:
subset[subset.bl.str.contains("stoke city")] the column bl of object type.
yet when run it, have error:
typeerror: data type not understood
how go fixing it?
update:
i tried using:
subset[subset.bl.astype(str).str.contains("stoke city")] but returned:
unicodeencodeerror: 'ascii' codec can't encode character u'\xa3' in position 37: ordinal not in range(128)
i tried resolving that:
subset.bl = subset.bl.str.encode("utf-8") that worked, returned same error:
'data type not understood error'
when again tried:
subset[subset.bl.astype(str).str.contains("stoke city")]
you can try cast str astype, because object can else string:
subset[subset.bl.astype(str).str.contains("stoke city")] you can check type of first value by:
type(subset.ix[0, 'bl']) edit:
you can try:
subset[subset.bl.str.encode("utf-8").str.contains("stoke city")] or:
subset['bl'] = subset.bl.str.encode("utf-8") subset[subset.bl.str.contains("stoke city")]
Comments
Post a Comment