datavinci
datavinci

Reputation: 807

How to change the type of pandas Data Frame column which initially is of type category?

I have the following columns in my data frame df:

df.dtypes
MeanTemperatureC              int64
MaxTemperatureC             float64
MinTemperatureC               int64
DewPointC                     int64
MeanDewPointC                 int64
MinDewpointC                  int64
MaxHumidity                   int64
MeanHumidity                  int64
MinHumidity                   int64
MaxSeaLevelPressurehPa        int64
MeanSeaLevelPressurehPa     float64
MinSeaLevelPressurehPa        int64
MaxVisibilityKm               int64
MeanVisibilityKm            float64
MinVisibilitykM             float64
MaxWindSpeedKm/h              int64
MeanWindSpeedKm/h             int64
MeanTemperatureCT          category
dtype: object

And I would like to change the datatype of the column 'MeanTemperatureCT' to str. I already tried the following:

df['MeanTemperatureCT'].astype(np.str)

And it did not change the datatype.So please,help.

Upvotes: 1

Views: 2207

Answers (1)

user3103874
user3103874

Reputation: 98

df['MeanTemperatureCT']= df['MeanTemperatureCT'].astype(str)

Upvotes: 5

Related Questions