Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

dataframe 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 :: check if id is present in elasticsearch using python 
Python :: python json string indices must be integersAdd Answer 
Python :: linkedin bot python 
Python :: python for loop skip iteration if condition not met jinja 
Python :: pandas maxima and minima for given column 
Python :: how to close python in terminal 
Python :: ring Insert Items in list 
Python :: ring retrieves the list of all algorithms supported by Encrypt()/Decrypt() functions. 
Python :: found django install path 
Python :: z3 symbolic expressions cannot be cast to concrete boolean values 
Python :: vue django delimiters 
Python :: How to Load Any HuggingFace Model in spaCy 
Python :: ret, img_frame = cap.read() 
Python :: python loc id in list 
Python :: fibonacci sphere python 
Python :: sympy.diff 
Python :: colorgram.py 1.2.0 
Python :: python if not explaned 
Python :: where are dictd dictionaries 
Python :: KMeans 
Python :: mail.send_message flask not working, SSL == 465 
Python :: python random number 1 100 
Python :: calling function whose name is in a variable 
Python :: vs code notes extension 
Python :: Which function is used to write all the characters? 
Python :: decode base64 password python 
Python :: sensing keyboard shortcuts using python 
Python :: to_csv zip pandas 
Python :: Create Tables From Migration 
Python :: import starting with number 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =