RockJake28 - 8 months ago 77

Python Question

For a list of numbers ranging from

`x`

`y`

`NaN`

`NaN`

`NaN`

Typically I would use

`MinMaxScaler`

`sklearn.preprocessing`

`NaN`

`NaN`

Answer

consider `pd.Series`

`s`

```
s = pd.Series(np.random.choice([3, 4, 5, 6, np.nan], 100))
s.hist()
```

*Option 1*

Min Max Scaling

```
new = s.sub(s.min()).div((s.max() - s.min()))
new.hist()
```

**NOT WHAT OP ASKED FOR**

I put these in because I wanted to

*Option 2*

sigmoid

```
sigmoid = lambda x: 1 / (1 + np.exp(-x))
new = sigmoid(s.sub(s.mean()))
new.hist()
```

*Option 3*

tanh (hyperbolic tangent)

```
new = np.tanh(s.sub(s.mean())).add(1).div(2)
new.hist()
```

Source (Stackoverflow)