text_plain_output_2.png text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

df = pd.read_csv('../input/titanic/train.csv')
test_df = pd.read_csv('../input/titanic/test.csv')

def detect_NaNs(df_temp: pd.DataFrame, name='', silent: bool=False, plot: bool=True):
    """
    Detect NaNs in a provided dataframe and return the columns that NaNs were detected in     
    Parameters
    ----------
    df_temp : pd.DataFrame
        Dataframe to detect NaN values in
    name : str
        Name of the dataframe which helps give a more descriptive read out
    silent : bool
        Whether the print statements should fire
    plot : bool
        Whether to return a plot of the counts of NaNs in the data
    Returns
    -------
    typing.List
        List of columns in the provided dataframe that contain NaN values
    """
    count_nulls = df_temp.isnull().sum().sum()
    columns_with_NaNs = []
    if count_nulls > 0:
        for col in df_temp.columns:
            if df_temp[col].isnull().sum().sum() > 0:
                columns_with_NaNs.append(col)
    return columns_with_NaNs

nan_columns = detect_NaNs(df, 'Training Data')