✍Tips and Tricks in Python

What is the difference between NaN ,None, pd.nan and np.nan?

Ke Gui
3 min readAug 28, 2020
Photo by Dave Gandy under the Public Domain Dedication License

Warning: There is no magical formula or Holy Grail here, though a new world might open the door for you.

📈Python For Finance Series

  1. Identifying Outliers
  2. Identifying Outliers — Part Two
  3. Identifying Outliers — Part Three
  4. Stylized Facts
  5. Feature Engineering & Feature Selection
  6. Data Transformation
  7. Fractionally Differentiated Features
  8. Data Labelling
  9. Meta-labeling and Stacking

TL;NR:

  • First of all, there is no pd.nan, but do have np.nan.
  • if a data is missing and showing NaN, be careful to use NaN ==np.nan. np.nan is not comparable to np.nan... directly.
np.nan == np.nanFalse

NaN is used as a placeholder for missing data consistently in pandas, consistency is good. I usually read/translate NaN as “missing”. Also see the ‘working with missing data’ section in the docs.

Wes writes in the docs ‘choice of NA-representation’:

--

--

Ke Gui

An ordinary guy who wants to be the reason someone believes in the goodness of people. He is living at Brisbane, Australia, with a lovely backyard.