0

I have a column with text which is stored as a object tpye in a pandas dataframe. The following two codes to not work. The required column is still object type.

TD_Eco_Comb_c['CountryPair'] = TD_Eco_Comb_c['CountryPair'].astype('|S')
TD_Eco_Comb_c['CountryPair'] = TD_Eco_Comb_c['CountryPair'].astype('str')

Any advice?

1

1 Answer 1

1

A string is always going to have dtype == 'object' in a dataframe.

This comes from numpy, which uses purely numerical dtypes. Everything that isn't numerical is classified as an 'object'. Your data is already in the format you need it to be in.

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

3 Comments

Thank you. How is it possible to show this than in a heatmap or visualize it. The problem is I can not plot it.
ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
I don't think I understand your questions, but they seem like they're better suited for an entirely new question rather than trying to expand on this one, which was "why can't I convert this to 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.