Reputation: 690
I'm using Pandas to strip a '$' out of some strings in a column.
df['Amount'].dtypes` --> `dtype('O')
So, I figure I can do string modification now:
df['Amount'].apply(lambda x: x.replace('$', ''))
I get the error: 'float' object has no attribute 'replace'
.
Why would the type "Object" (string) but be "float" when I'm operating on it?
Upvotes: 1
Views: 192
Reputation: 261850
Object doesn't mean string, it means not a homogeneous vectorizable dtype.
You can use:
df['Amount'].astype(str).str.replace('$', '')
Upvotes: 4