Reputation: 1092
I have a dataframe and when I do df.dtypes
in shows the column is an object
I do df["column_name"] = df["column_name"].astype(str)
and again check df.dtypes it still shows the column type as object. Any idea bow to fix this.
When I do df['column_name'].to_string().dtype
I get an error
AttributeError: 'unicode' object has no attribute 'dtype'
Upvotes: 0
Views: 990
Reputation: 1
Series can be converted to the string datatype, give this a try:
df['column_name'] = pd.Series(df['column_name'], dtype="string")
Or give this a try
df['column_name']=df.column_name.convert_dtypes()
Upvotes: 0
Reputation: 670
In Pandas, there are only these datatypes: boolean, integer, float, datetime and object. Objects are almost always strings but can be any Python object. This is the reason why df.dtypes shows an object.
Upvotes: 1