Plot null values



    Wyx Smrf


    Create a count plot of null values in a DataFrame. Uses the x-axis as the columns and uses y-axis as the numeric counts.

    Filename pattern: .ipynb, .py

    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt
    def null_plot(data):
      """Create a plot that shows the counts of null values for each column that contains one
        data (DataFrame): Two-dimensional data structure stored in a tabular format
        AxesSubplot: Graph of countplot of null values
      # Determine the columns that have null values
      def listed_null_cols():
        """Determine which column/s contains null values
          list: Columns in the DataFrame that have null values
        null_columns = data.columns[data.isna().any()]
        return null_columns.tolist()
      # Retrieve the null values in the data
      null_columns = data[listed_null_cols()]
      null_rows = null_columns.loc[null_columns.isna().any(axis=1)]
      # Unpivot the data cosisting of null values
      melted_data = pd.melt(null_rows)
      melted_nulls = melted_data[melted_data['value'].isnull()]
      # Plot the null values
      sns.countplot(data=melted_nulls, x=melted_nulls['variable'])
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.