I have a data frame with some cell values such as $1,245 which are interpreted as objects.
How can I write a lambda function to remove the '$' and ',' and cast to float in only cells whose entry contains a '$'?
I was able to get it working without the if-else before. but that also messed up other string columns that do not have $ in them.
df = df.apply(lambda x: x.str.replace('[$,]',
'').astype(float) if '$' in x else x)
Sample Data:
Programmer, Hawaii,"$115,887","$9,657","$2,229",$55.72
Engineering Manager, West Virginia,"$115,420","$9,618","$2,220",$55.49
Data Scientist, Pennsylvania,"$114,863","$9,572","$2,209",$55.22