1

i have a Pandas DataFrame with the following structure.

Feature 1  | Feature 2  | Feature 3
10         | 200        | True
30         | 233        | False
45         | 344        | True

any idea how i can do normalization for feature 1 and feature 2 only? without changing the index of original DataFrame.

i already try this following code, but it's normalize all columns and change the index of dataframe to 0,1,2

x = df.values
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
dataset = pd.DataFrame(x_scaled)

1 Answer 1

4

Just create a view of your dataframe:

x = df[['Feature 1', 'Feature 2']]
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
dataset = pd.DataFrame(x_scaled)
dataset['Feature 3'] = df['Feature 3']
Sign up to request clarification or add additional context in comments.

2 Comments

it's work, but i have to include 'feature 3' too (without normalization) in new dataset.
check the update (notice that your sample data has no index, so it should work)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.