ShuFFle2207
ShuFFle2207

Reputation: 87

Object Type not convertable in string Python

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?

Upvotes: 0

Views: 45

Answers (1)

wpercy
wpercy

Reputation: 10090

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.

Upvotes: 1

Related Questions