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 :: Like strings (and all other built-in sequence type), lists can be indexed and sliced: 
Python :: shere point file uploading to doc repository python 
Python :: connect labjack to python 
Python :: Best websites to learn Python 
Python :: get the first principle component of pca 
Python :: replace string in dictionary python 
Python :: ring Access List Items by String Index 
Python :: dictionary, accepting similar words solution 
Python :: negative max in python 
Python :: list duplicates of specific file in folder python 
Python :: django bring specific values first 
Python :: Python loop aray 
Python :: salamelecus 
Python :: Proper Case django template 
Python :: Convert matlab to Python Reddit 
Python :: regression avec sklearn best 
Python :: plt.axes muktiple plots 
Python :: FinnT730 
Python :: python making player equipment 
Python :: cv2 warpaffine rotate 
Python :: Pandas: Filter column value in array/list - ValueError: The truth value of a Series is ambiguous 
Python :: keras model predict list of input tensors 
Python :: alexa in python 
Python :: set application taskbar icon 
Python :: how to add import pydictionary in python 
Python :: changing correlation encoding values 
Python :: mongoclient python 
Python :: loop until counted to 100 forever 
Python :: python threadpool map exception 
Python :: Drop a single column by index 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =