Код: Выделить всё
age
0 48
1 7
2 62
3 48
4 51
Код: Выделить всё
import pandas as pd
import numpy as np
def normalizar(x):
# Convert x to a numpy array to allow for vectorized operations.
x = np.array(x)
# Calculate the minimum and maximum values of x.
xmin = x.min()
xmax = x.max()
# Normalize the array x using vectorized operations.
return (x - xmin) / (xmax - xmin)
df["age_n"] = df["age"].apply(normalizar)
df
Код: Выделить всё
age age_n
0 48 NaN
1 7 NaN
2 62 NaN
3 48 NaN
4 51 NaN
Ожидаемым результатом будут значения между [0,1]
Подробнее здесь: https://stackoverflow.com/questions/790 ... a-function