Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to replace the NaN value by zero in python?

Description

To replace the NaN(missing value) by scalar value using python.

Process

   Import pandas library.

   Read the sample data.

   Make it as a data frame.

   Use fillna() to replace Nan value.

Sample Code

#import libraries

import pandas as pd

#Read the sample data

data=pd.read_csv(‘/home/soft27/soft27/

Sathish/Pythonfiles/Houseprice.csv’)

#create data frame

df=pd.DataFrame(data)

print(“Actual data frame is:\n”,df)

#Find the missing values

print(“Find missing values”)

print(df.isnull())

#Replace the missing values(Nan)

print(“Replace the Nan values”)

print(df.fillna(0))

Screenshots
replace the NaN value by zero in python
import libraries
Replace the missing values(Nan)