Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

replace all missing value with mean pandas

column_means = df.mean()
df = df.fillna(column_means)
Comment

Replace with missing values for numerical columns with mean

IN:
#Replace the missing values for numerical columns with mean
train_df['LoanAmount'] = train_df['LoanAmount'].fillna(train_df['LoanAmount'].mean())
train_df['Credit_History'] = train_df[‘Credit_History'].fillna(train_df['Credit_History'].mean())

OUT:
Loan_ID  0
Gender  13
Married  3
Dependents  15
Education  0
Self_Employed 32
ApplicantIncome  0
CoapplicantIncome  0
LoanAmount 0
Loan_Amount_Term 0
Credit_History 0
Property_Area  0
Loan_Status  0
dtype: int64
Comment

PREVIOUS NEXT
Code Example
Python :: No package python37 available. 
Python :: how to sum only the even values in python 
Python :: python bool to string 
Python :: plotly hide color bar 
Python :: replace value pandas df 
Python :: python: measure time code 
Python :: pandas profile 
Python :: correlation python 
Python :: python get pixel color from screen 
Python :: how to find the location of a character in a string in python 
Python :: sklearn cross_val_score scoring metric 
Python :: django login_required decorator 
Python :: python append a file and read 
Python :: how to read excel file in python 
Python :: sort rows in csv file using python pandas 
Python :: Import A Model 
Python :: create new dataframe with columns from another dataframe pandas 
Python :: how to delete json object using python? 
Python :: how to get input python 
Python :: csv library python convert dict to csv 
Python :: unshorten url python 
Python :: make python3 default in ubuntu 
Python :: how to get user id from username discord.py 
Python :: python how to check if a functions been called 
Python :: registration of path in urls.py for your apps for views 
Python :: print alphabets in python 
Python :: multiple variables in for loop python 
Python :: wordle python 
Python :: read csv and store in dictionary python 
Python :: multiply each element in list python 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =