How to Replace NaN with Average of Columns in Pandas?

Spread the love

Problem –

You want to replace NaN with average of columns in Pandas.

Solution –

Read a dataset to work with.

import pandas as pd

url = ''
df = pd.read_csv(url)

To replace the NaN with average of the columns you have to write.

df.fillna(df.mean(), inplace=True)

Rating: 1 out of 5.

Leave a Reply