NaN in mapper – name ‘nan’ is not defined

Python does not have a built-in name nan, nor is there a keyword.

It looks as if you forgot to import it; numpy defines such a name:

from numpy import nan

From the local name df I infer you are probably using pandas; pandas’ documentation usually uses np.nan, where np is the numpy module imported with import numpy as np. See their 10 Minute to pandas intro for example.

Leave a Comment