Oct-02-2019, 01:06 AM
Hey all,
Ive been working on creating plots and am trying to convert a column that had $4,312.00 as an Object instead of a float or integer.
In order to do so, I had to remove some characters with the following code
Now, after removing those characters, I'm getting an error message that says
Error could not convert string to float:
I checked the output of the column, and from what I can tell, it's all good. HEre's a sample.
Thank you.
Ive been working on creating plots and am trying to convert a column that had $4,312.00 as an Object instead of a float or integer.
In order to do so, I had to remove some characters with the following code
member_clean.AverageCheckingBalance = member_clean.AverageCheckingBalance.str.replace('$', '') #strip spaces in TotalDepositBalanes which prevents it from being converted to a float member_clean['AverageCheckingBalance'] = member_clean['AverageCheckingBalance'].str.strip() member_clean.AverageCheckingBalance = member_clean.AverageCheckingBalance.str.replace(',', '') member_clean.AverageCheckingBalance = member_clean.AverageCheckingBalance.str.replace(' ', '') member_clean['AverageCheckingBalance'] = member_clean['AverageCheckingBalance'].astype(float)Basically, each character I removed with the code above besides the $, an error message told me to remove.
Now, after removing those characters, I'm getting an error message that says
Error could not convert string to float:
I checked the output of the column, and from what I can tell, it's all good. HEre's a sample.
Output:0 498.09
1 79.40
3 6022.23
5 3024.94
6 548.34
I checked for null values, i think I checked for an empty line as well (not sure I did this one correctly, though) but nothing is coming up other than output similar to that posted above. Is there something wrong be the code Ive written to convert it to a float? I tried this with another column as well and I'm getting the same error, so I really think it has to be with the code and not the values, but I don't know for sureThank you.