Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

EDA describe missing and zero values

def describe_missing_zeros_values(df: pd.core.frame.DataFrame) -> pd.core.frame.DataFrame:
    """Describe Missing and Zero Valued columns in a dataframe.
    
    Args:
        df (pd.core.frame.DataFrame): Dataframe under analysis.
        
    Returns:
        pd.core.frame.Dateframe: Dataframe with missing and zero valued columns and their statistics.
    """
    zero_values = (df == 0.00).astype(int).sum(axis=0)
    missing_values = df.isnull().sum()
    missing_values_percent = missing_values * 100 / len(df)
    missing_zero_df = pd.concat([zero_values, missing_values, missing_values_percent], axis=1)
    missing_zero_df = missing_zero_df.rename(
                            columns = {0 : "Zero Values", 1 : "Missing Values", 2 : "% Missing Values"})
    missing_zero_df["Total Zero & Missing Values"] = missing_zero_df["Zero Values"] + missing_zero_df["Missing Values"]
    missing_zero_df["% Total Zero & Missing Values"] = 100 * missing_zero_df["Total Zero & Missing Values"] / len(df)
    missing_zero_df["Data Type"] = df.dtypes
    missing_zero_df = missing_zero_df[missing_zero_df.iloc[:,1] != 0].sort_values("% Missing Values", ascending=False).round(1)
    print(f"Your selected dataframe has {df.shape[0]} rows {df.shape[1]} columns.")
    print(f"There are {missing_zero_df.shape[0]} columns that have missing values.")
    return missing_zero_df
Comment

PREVIOUS NEXT
Code Example
Python :: dataframe get missing and zero values 
Python :: Invenco Order Dict 
Python :: python static 
Python :: self.stdout.write django 
Python :: python discord next page 
Python :: list foreach pyhton 
Python :: ring Reverse List Item 
Python :: ring PostgreSQL load the postgresqllib.ring library 
Python :: while loop using increment 
Python :: word cloud mape python 
Python :: loop over dict python looking for match in list 
Python :: how to dynamically append value in a list in python 
Python :: update a variable in torch 
Python :: how to store file into folder bucket aws 
Python :: df.write using another delimiter 
Python :: Python 2.7 to 3.x Linux 
Python :: Python Root finding code 
Python :: how to bubble search in python stack overflow 
Python :: object creation using class constructor 
Python :: opencv houghlines only horizontal 
Python :: python program to multiply two numbers and multiply the answer with 2nd variables 
Python :: python send email with attachment 
Python :: eager tensor to numpy 
Python :: convert numpy array to byteslist 
Python :: Which function is used to read single line from file? 
Python :: run selenium webdriver without opening browser 
Python :: deploy vue app to google cloud run 
Python :: As a general rule in python 
Python :: matplotlib add abline 
Python :: import * with __import__ 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =