0

I have this code which replaces all spaces/gaps within my data structure with NaN:

replace_spaces = data.replace(r'^\s*$', np.nan, regex=True)

How would I update that to make it so converts all: space, empty, N/A, na and NA type values into NaN for consistency ?

And how would I return the location of these empty strings? (I've been googling for hours couldn't find solution)

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
Bexa
  • 1
  • 1
  • I think it would be better to check if the value is the numerical type you expect and replace any which are not with NaN . – JeffUK Nov 29 '20 at 22:31
  • Since you tagged this question with `pandas`, If you're using pandas, you might want to take a look at the `na_values` argument of `read_csv`, you might be able to take care of it all when you read in your data – sacuL Nov 29 '20 at 22:31
  • Does this answer your question? [How do I check if a string is a number (float)?](https://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-number-float) – JeffUK Nov 29 '20 at 22:31

1 Answers1

0

Thanks sacuL :) I done this

data = pd.read_csv(file,keep_default_na=False, na_values=missing_values) ```

And it's work :D

Bexa
  • 1
  • 1