How to normalise COLUMN in Pandas DataFrame in Python

January 11, 2019

Contact Seller

Guest Post Description

How to normalise COLUMN in Pandas DataFrame in Python

def Kickstarter_Example_96(): 
    print()
    print(format('How to Normalise a Pandas DataFrame Column','*^82'))    
    import warnings
    warnings.filterwarnings("ignore")
    # load libraries
    import pandas as pd
    from sklearn import preprocessing
    # Create an example dataframe with a column of unnormalized data
    data = {'score': [234,24,14,27,-74,46,73,-18,59,160]}
    df = pd.DataFrame(data)
    print(); print(df)
    # Normalize The Column
    # Create x, where x the 'scores' column's values as floats
    x = df[['score']].values.astype(float)
    print(); print(x)
    # Create a minimum and maximum processor object
    min_max_scaler = preprocessing.MinMaxScaler()
    # Create an object to transform the data to fit minmax processor
    x_scaled = min_max_scaler.fit_transform(x)
    # Run the normalizer on the dataframe
    df_normalized = pd.DataFrame(x_scaled)
    # View the dataframe
    print(); print(df_normalized)
Kickstarter_Example_96()

How to normalise COLUMN in Pandas DataFrame in Python

Add a Review

You must be logged in to post a comment.