quinn-dougherty / sketch-mvp-house

will move this to organization or delete it when the time comes.
0 stars 1 forks source link

need to improve stripping dollar from strings like `"$ 21,543.34"` and casting to float #3

Open quinn-dougherty opened 5 years ago

quinn-dougherty commented 5 years ago

This function needs attention.

as currently implemented, it is correct on a test like assert try_float_cash("$ 45.29")==45.29

right now, the behavior is incorrect on the following test: assert try_float_cash("$1,345.29")==1345.29


def try_float_cash(x):
            ''' get a `$` out of what's supposed to be a number 

            TODO: fix incorrect behavior: e.g. `assert try_float_cash("$1,345.29")==1345.29` '''
            try:
                return float('.'.join(re.findall(r'\d+', x)))
            except TypeError:
                return x
            except ValueError:
return x```
quinn-dougherty commented 5 years ago

it's possible we'll factor out this function in new feature engineering and data cleaning code.