Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

EDA dataframe get 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 :: OddOccurrencesInArray 
Python :: np sign no 0 
Python :: ax pie rounding 
Python :: parseint python equivalent 
Python :: perform cross tabulation sklearn 
Python :: converter json em form-data-encoded python 
Python :: ring Using Lists during definition 
Python :: ring write the key and the IV directly using strings 
Python :: easy ocr python pypi 
Python :: list duplicate files in folder python 
Python :: check string on substring godot 
Python :: if dict json 
Python :: purge python3.y from every place in my path 
Python :: element wise mean and std 
Python :: what is primary key in python 
Python :: python strip txt 
Python :: django save another class data while saving a class 
Python :: python min date from dictionary 
Python :: legend outside subplot not displayed 
Python :: python how to dump exception stak 
Python :: python post np.array object 
Python :: diamond shape alphabatical pattern program in python 
Python :: pyqt highlight all occurrences of selected word qt 
Python :: edit packet in scapy 
Python :: jumpssh execute multiple commands 
Python :: pandas iat 0 
Python :: Joint Grid plot in seaborn 
Python :: writer.append_data(image) means 
Python :: Overwrite text in python 
Python :: drop columns by name 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =