All Courses

# not able to replace Null values with mean, median, mode. Now left with with arbitary value

##### By Pp5344229@gmail.com, 3 months ago

I am not able to replace Null values with mean, median, mode. Now left with with arbitary value . please give me hint how to do that

Null values
Mean
Mode
Median

Basically arbitary value is when you try to replace one value with another like null to others

##### Goutamp777

To replace null values with the mean, median, or mode of a column, you can use the following approaches:

Mean:

You can use the `mean()` function from Pandas to calculate the mean of a column. Then you can use the `fillna()` function to replace null values with the mean. Here's an example:

import pandas as pd

# Calculate the mean of the column

mean = df["column_name"].mean()

# Replace null values with the mean

df["column_name"].fillna(mean, inplace=True)

Median:

You can use the `median()` function from Pandas to calculate the median of a column. Then you can use the `fillna()` function to replace null values with the median. Here's an example:

import pandas as pd

# Calculate the median of the column

median = df["column_name"].median()

# Replace null values with the median

df["column_name"].fillna(median, inplace=True)

Mode:

You can use the `mode()` function from Pandas to calculate the mode of a column. Then you can use the `fillna()` function to replace null values with the mode. Here's an example:

import pandas as pd

# Calculate the mode of the column

mode = df["column_name"].mode()

# Replace null values with the mode

df["column_name"].fillna(mode, inplace=True)

If you want to use an arbitrary value to replace the null values, you can use the `fillna()` function as shown in the examples above and pass the arbitrary value as an argument to the function.

#### Live Masterclass on : "How Machine Get Trained in Machine Learning?" Mar 30th (7:00 PM) 516 Registered
More webinars

#### Related Discussions

Running random forest algorithm with one variable

View More