Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

fill na with mode and mean python

cateogry_columns=df.select_dtypes(include=['object']).columns.tolist()
integer_columns=df.select_dtypes(include=['int64','float64']).columns.tolist()

for column in df:
    if df[column].isnull().any():
        if(column in cateogry_columns):
            df[column]=df[column].fillna(df[column].mode()[0])
        else:
            df[column]=df[column].fillna(df[column].mean)
Comment

PREVIOUS NEXT
Code Example
Python :: python check list contains another list 
Python :: how to use enumerate instead of range and len 
Python :: python blowfish 
Python :: how to auto update chromedriver selenium python 
Python :: log base in python 
Python :: get all count rows pandas 
Python :: b1-motion tkinter 
Python :: numpy replace 
Python :: convert categorical column to int in pandas 
Python :: frequency unique pandas 
Python :: python disable warning deprecated 
Python :: python faker 
Python :: openpyxl write in cell 
Python :: spacy remove stop words 
Python :: tqdm parallel 
Python :: python create a matrix with one in diagonal 
Python :: python sorting array without inbuilt sort 
Python :: converting pandas._libs.tslibs.timedeltas.Timedelta to days 
Python :: How to replace both the diagonals of dataframe with 0 in pandas 
Python :: python open pickle file 
Python :: Python pandas drop any row 
Python :: pip show all installed packages 
Python :: how to find index of second largest number in array python 
Python :: python pandas convert comma separated number string to integer list 
Python :: python format decimal 
Python :: how to convert an image to matrix in python 
Python :: read xls file in python 
Python :: scaling image interpolation python 
Python :: python print int in string with zero padding 
Python :: how to change canvas background color in python tkinter 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =