This question seems very basic and the topic was clearly answered in this question : Change data type of columns in Pandas
I have a DataFrame df
.
One column is named adress
and contains strings :
type(df.loc[0, 'adress'])
>>> str
#Let's check the whole column's type
df.loc[:, 'adress'].dtype
>>> dtype('O')
The dtype is an object, I would like to change it to a string. I tried :
df.loc[:, 'adress'] = df.loc[:, 'adress'].astype(str)
df.loc[:, 'adress'].dtype
>>> dtype('O')
#and
df.loc[:, 'adress'] = df.loc[:, 'adress'].astype('str')
df.loc[:, 'adress'].dtype
>>> dtype('O')
#and
df = df.infer_objects()
df.loc[:, 'adress'].dtype
>>> dtype('O')
I have no idea what I am missing.
I aslo checked that the whole column contains only strings :
for i in df.index:
if type(df.loc[i, 'adress']) != str:
print(i)
wait = input('Up')
print('Done')
>>>Done