How to Normalise a Pandas DataFrame Column?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to Normalise a Pandas DataFrame Column?

How to Normalise a Pandas DataFrame Column?

This recipe helps you Normalise a Pandas DataFrame Column

0
In [1]:
## How to Normalise a Pandas DataFrame Column
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 a Pandas DataFrame Column********************

   score
0    234
1     24
2     14
3     27
4    -74
5     46
6     73
7    -18
8     59
9    160

[[234.]
 [ 24.]
 [ 14.]
 [ 27.]
 [-74.]
 [ 46.]
 [ 73.]
 [-18.]
 [ 59.]
 [160.]]

          0
0  1.000000
1  0.318182
2  0.285714
3  0.327922
4  0.000000
5  0.389610
6  0.477273
7  0.181818
8  0.431818
9  0.759740

Relevant Projects

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Data Science Project-All State Insurance Claims Severity Prediction
Data science project in R to develop automated methods for predicting the cost and severity of insurance claims.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.