Question: I am trying to **REPLACE** some values on a certain column in my data set.

\*(*Notice the presence of NaN entries)*

**Column**: `Name`

**Values**: 

```
OLIVER 
HARRY 
OLIVER
NaN
HARRY
NaN

```

By performing the following:

```
df['Name'] = 'User' + pd.Series(pd.factorize(df['Name'])[0] + 1).astype(str)

```

I get mostly what i want:

**Values**: 

```
User1
User2
User1
User0
User2
User0

```

The problem is that i need my *NaN* values to remain as *NaN*. The processing should ignore *NaN* column values and leave them as such, getting something like:

**Values**: 

```
User1
User2
User1
NaN
User2
NaN

```

How can this be done?

Answer: 
How about

```
import numpy as np

df['Name'] = np.where(df['Name'].isna(), df['Name'],'User' + pd.Series(pd.factorize(df['Name'])[0] + 1).astype(str))

```

This will not replace the `nan`-entries but simply leave them as they were. 

Basically the `where`function takes an array of boolean values, in this case `df['Name'].isna()`, and uses values from the array given as the second argument wherever this evaluates to `True`, and values from the array given as the third argument otherwise.
An alternative is to create a dict from your `Name` column and map it:

```
names = {n:"User{}".format(i) for i, n in enumerate(df["Name"].unique())}
df["Name"] = df["Name"].map(names)

```