I am trying to convert a pandas column from a str to a float. Before I convert the strings to floats using astype(float), I need to remove characters from the string which cannot be converted into floats, like a comma or a space. In trying to remove these characters, I am using list compression and the str.replace method like this:
data.loc[:,'column_name'] = [char.replace(',', '') for char in
data.loc[:,'column_name']]
but I am getting an error saying:
AttributeError: 'float' object has no attribute 'replace'.
The confusing part, though, is that when I look at the dtypes, the dtype for that column shows up as 'o', or object. So I have no idea what is going on.