“Normalizuj dane Python Pandas” Kod odpowiedzi

Normalizuj dane Python Pandas

import pandas as pd
from sklearn import preprocessing

x = df.values #returns a numpy array
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
df = pd.DataFrame(x_scaled)
Exuberant Eel

Pandy normalizują DF

# min-max normalization:
df=(df-df.min())/(df.max()-df.min())

# or...

# mean normalization:
df=(df-df.mean())/df.std()
FishBrawler

Normalizuj dane Python

>>> from sklearn import preprocessing
>>>
>>> data = [100, 10, 2, 32, 31, 949]
>>>
>>> preprocessing.normalize([data])
array([[0.10467389, 0.01046739, 0.00209348, 0.03349564, 0.03244891,0.99335519]])
Gifted Gull

Funkcja do skalowania funkcji w DataFrame

# define a method to scale data, looping thru the columns, and passing a scaler
def scale_data(data, columns, scaler):
    for col in columns:
        data[col] = scaler.fit_transform(data[col].values.reshape(-1, 1))
    return data
Cheerful Cheetah

Odpowiedzi podobne do “Normalizuj dane Python Pandas”

Pytania podobne do “Normalizuj dane Python Pandas”

Więcej pokrewnych odpowiedzi na “Normalizuj dane Python Pandas” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu