I have a column which has text in it. I have to replace (':',' ').
When I am running this code:
df["text"] = [x.replace(':',' ') for x in df["text"]]
I am facing the this error:
AttributeError: 'float' object has no attribute 'replace'
AttributeError Traceback (most recent call
last)
<ipython-input-13-3c116e6f21e2> in <module>
1 #df["text"] = df["text"].astype(str)
----> 2 df["text"] = [x.replace(':',' ') for x in df["text"]]
<ipython-input-13-3c116e6f21e2> in <listcomp>(.0)
1 #df["text"] = data["NOTES_ENT"].astype(str)
----> 2 df["text"] = [x.replace(':',' ') for x in df["text"]]
AttributeError: 'float' object has no attribute 'replace'
The error is pretty clear. you are trying to replace characters in a float. x probably is a float. you might want to do str(x) which gets you
f["text"] = [str(x).replace(':',' ') for x in df["text"]]
but i can't see a situation where a float contains a :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With