I have a file that lists deposit balances as strings. IN order to plot these numbers, I'm trying to convert the Objects to a float. So I wrote code to remove the $ and to take out spaces before and after the values.
member_clean.TotalDepositBalances = member_clean.TotalDepositBalances.str.replace('$', '')
member_clean['TotalDepositBalances'] = member_clean['TotalDepositBalances'].str.strip()
member_clean['TotalDepositBalances'] = member_clean['TotalDepositBalances'].astype(float)
When I run the code, I get an error message that says
ValueError: could not convert string to float:
That's it. Before I added the str.strip, the error message showed me that some values had spaces before and after, so I knew to remove those. But I'm a little confused what else is causing it,
I looked at the values of the column after I removed the spaces and $, and everything looks normal. Here's a sample.
- 309.00
- 38.00
- 12,486.00
- 6,108.00
- 2,537.00
Any ideas of what I could check for in the columns that may be causing this error