-3

If I have a variable with missings, how do I assign them as NaNs in python?

I've tried the following but it's returning an empty dataframe:

data_2017_18.income=np.nan

Much appreciated.

  • 1
    Look at this [answer](https://stackoverflow.com/a/5438756/10732434) from this [question](https://stackoverflow.com/questions/5438745/is-it-possible-to-set-a-number-to-nan-or-infinity). – sanitizedUser Jun 02 '20 at 12:30
  • Please clarify your question, add a [mre]. Are you working with `pandas`? If so, what do you want to achieve, what to you want to do with column 'income'? – FObersteiner Jun 02 '20 at 12:32
  • I'm looking to give all of the cases that have no data the value of 'NaN'. I did have a look at the above answer but it doesn't seem to be relevant? – johnny_trfc Jun 02 '20 at 13:48

1 Answers1

1

You can use float("nan") to get a "not a number" (NaN) value.

tfeldmann
  • 3,108
  • 1
  • 23
  • 34