> ## Content Index
> Fetch the complete content index at: https://datascientyst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# NameError: name 'nan' is not defined in Pandas and Python
- URL: https://datascientyst.com/nan-in-mapper-name-nan-is-not-defined-pandas-python/
- Published: 2022-08-17T10:21:27.000Z
- Updated: 2022-08-17T10:21:47.000Z
- Author: John D K
- Tags: map(), Pandas Error

In this tutorial, we'll see how to solve a common Pandas error:

> NameError: name 'nan' is not defined

or

> UndefinedVariableError: name 'nan' is not defined

We get this error from the Pandas or Python when `numpy` is not imported as a library.

## 1\. import numpy nan

By default numpy should be installed with Pandas. So to solve the error we need to import numpy `NaN` value we can use:

```python
from numpy import nan

```

×Note that 

NaN

 are aliases of 

nan

. 

The error is common for map operation in Pandas.

```python
mp = {'K':' * 10**3', 'M':' * 10**6', '< ': ''}
df['amount'] = pd.eval(df['amount'].replace(mp.keys(), mp.values(), regex=True).str.replace(r'[^\d\.\*]+',''))

```

The example above will result into:

> UndefinedVariableError: name 'nan' is not defined

## 2\. import numpy library

As alternative we can import the whole library or other parts from `numpy`:

```python
import numpy as np

```

This is described in: [10 minutes to pandas](https://pandas.pydata.org/pandas-docs/stable/user%5Fguide/10min.html?ref=datascientyst.com)

## 3\. install numpy

Finally if you need to install numpy library you can do it by:

```python
pip install numpy

```