HOWTO · Pandas

Three Ways to Normalize Numeric DataFrame Columns in Pandas

Compare mean (z-score) standardization, min-max scaling, and quantile normalization for numeric Pandas DataFrame columns, with formulas and reusable examples.

On this page

To rescale numeric columns in a Pandas DataFrame, choose among three approaches: mean normalization (z-score standardization) centers each column and scales by its standard deviation, min-max scaling maps each nonconstant column to 0–1, and quantile normalization maps values by rank toward a shared distribution. The right choice depends on the scale your model needs, sensitivity to outliers, and whether the columns should have comparable distributions.

Data Normalization in Pandas

Normalization rescales values, while standardization centers values around a mean and expresses them in standard-deviation units. This guide demonstrates three column-wise transformations. Pandas does not provide one dedicated DataFrame method for these formulas, but its arithmetic and ranking operations make each straightforward to implement.

The examples use the same small, deterministic DataFrame with four numeric columns. Each transformation works down each column, so columns retain their names and row indexes.

import pandas as pd


df = pd.DataFrame({
    "A": [1, 2, 3, 4],
    "B": [10, 20, 30, 40],
    "C": [4, 1, 3, 2],
    "D": [5, 5, 5, 5],
})

print(df)
   A   B  C  D
0  1  10  4  5
1  2  20  1  5
2  3  30  3  5
3  4  40  2  5

The D column is constant to make its behavior explicit in the min-max section. Examples below are self-contained and recreate this same input.

Normalize Pandas Dataframe With the mean Normalization

The mean-based formula is (x - mean) / standard deviation, computed separately for each column. This is z-score standardization: each transformed column has a mean near zero, and values are measured in standard-deviation units rather than constrained to 0–1. Pandas Series.std() uses the sample standard deviation (ddof=1) by default; use ddof=0 when your calculation calls for the population standard deviation.

import pandas as pd


df = pd.DataFrame({
    "A": [1, 2, 3, 4],
    "B": [10, 20, 30, 40],
    "C": [4, 1, 3, 2],
    "D": [5, 5, 5, 5],
})

mean_norm = df.apply(lambda column: (column - column.mean()) / column.std(), axis=0)
print(mean_norm.round(3))
       A      B      C   D
0 -1.162 -1.162  1.162 NaN
1 -0.387 -0.387 -1.162 NaN
2  0.387  0.387  0.387 NaN
3  1.162  1.162 -0.387 NaN

This transformation is useful when a method benefits from centered, comparable scales. A constant column has a standard deviation of zero, so this formula produces missing values for that column; decide whether to drop such a feature or handle it separately for your application.

Normalize Pandas Dataframe With the min-max Normalization

For each column, min-max scaling uses (x - min) / (max - min). The minimum and maximum of every nonconstant column become 0 and 1, with the other values placed proportionally between them. The helper below uses its df_input argument throughout and maps a constant column to 0, a common neutral choice when a feature carries no variation.

import pandas as pd


def minmax_norm(df_input):
    column_range = df_input.max() - df_input.min()
    scaled = (df_input - df_input.min()) / column_range
    return scaled.fillna(0)


df = pd.DataFrame({
    "A": [1, 2, 3, 4],
    "B": [10, 20, 30, 40],
    "C": [4, 1, 3, 2],
    "D": [5, 5, 5, 5],
})

print(minmax_norm(df).round(3))
       A      B      C    D
0  0.000  0.000  1.000  0.0
1  0.333  0.333  0.000  0.0
2  0.667  0.667  0.667  0.0
3  1.000  1.000  0.333  0.0

Min-max scaling is suitable when a fixed range matters. Because the observed minimum and maximum set the scale, an extreme value can compress the rest of that column into a narrow interval. The helper’s final fillna(0) maps constant numeric columns to 0, but it also replaces every missing value already present in the input with 0. If you prefer mean imputation, fill missing values before calling the helper, for example minmax_norm(df_input.fillna(df_input.mean())); choose an imputation policy that fits your data.

Normalize Pandas Dataframe With the quantile Normalization

Quantile normalization is useful when the columns are expected to share the same underlying distribution. It sorts each column, averages the sorted values at each rank across columns, then maps those rank averages back to the original rows. Unlike the other two methods, it changes values to align the columns’ empirical distributions, so use it only when that shared-distribution assumption is appropriate.

This implementation uses rank(method="min"): tied values receive the smallest rank in their tie group. It does not average tied ranks, so ties can make the resulting distributions differ. In the shared example, column D is constant: all four values tie at the minimum rank, so they map to the same rank average rather than spanning the shared rank values.

import numpy as np
import pandas as pd


def quantile_norm(df_input):
    sorted_values = np.sort(df_input.to_numpy(), axis=0)
    rank_means = sorted_values.mean(axis=1)
    rank_to_mean = pd.Series(rank_means, index=np.arange(1, len(rank_means) + 1))
    ranks = df_input.rank(method="min").stack().astype(int)
    return ranks.map(rank_to_mean).unstack()


df = pd.DataFrame({
    "A": [1, 2, 3, 4],
    "B": [10, 20, 30, 40],
    "C": [4, 1, 3, 2],
    "D": [5, 5, 5, 5],
})

print(quantile_norm(df).round(3))
       A      B      C     D
0   4.25   4.25  13.25  4.25
1   7.25   7.25   4.25  4.25
2  10.25  10.25  10.25  4.25
3  13.25  13.25   7.25  4.25

The constant D column illustrates why the shared-distribution assumption matters: its repeated values all receive the minimum rank and map to 4.25, so it does not match the other columns’ empirical distributions. For ordinary numeric features, compare the methods by their goal: choose z-scores for centering and standard-deviation scaling, min-max for a bounded range with awareness of outliers, or quantile normalization when aligning column distributions is justified by the data.