11import numpy
22import pandas as pd
33
4- def check_null (dataframe : pd .DataFrame , columns_to_be_checked : list ) -> bool :
4+ def check_null (dataframe : pd .DataFrame , columns_to_be_checked : tuple ) -> bool :
55 """
66 Checks a pandas dataframe for null values
77
@@ -11,7 +11,7 @@ def check_null(dataframe: pd.DataFrame, columns_to_be_checked: list) -> bool:
1111 ----------
1212 data : pandas.DataFrame
1313 Dataframe to read
14- columns_to_be_checked: list
14+ columns_to_be_checked: tuple
1515 Given dataframe columns to be checked for null values
1616
1717 Returns
@@ -21,12 +21,18 @@ def check_null(dataframe: pd.DataFrame, columns_to_be_checked: list) -> bool:
2121
2222 Examples
2323 --------
24- >>> check_null(dataframe = pd.DataFrame({'col1': [1,2], 'col2': [3,4]}), columns_to_be_checked = [ 'col1'] )
24+ >>> check_null(dataframe = pd.DataFrame({'col1': [1,2], 'col2': [3,4]}), columns_to_be_checked = ( 'col1') )
2525 0
26- >>> check_null(dataframe = pd.DataFrame({'col1': [1,numpy.nan], 'col2': [3,4]}), columns_to_be_checked = [ 'col1'] )
26+ >>> check_null(dataframe = pd.DataFrame({'col1': [1,numpy.nan], 'col2': [3,4]}), columns_to_be_checked = ( 'col1') )
2727 1
2828 """
2929
30+ for eachVal in columns_to_be_checked :
31+ if type (eachVal ) != str :
32+ raise ValueError ("Please input string values for column names." )
33+ if columns_to_be_checked not in dataframe .columns :
34+ raise KeyError ("Please check the column names correspond to values in the DataFrame." )
35+
3036 null_count = 0
3137 for eachColumn in columns_to_be_checked :
3238 prev_null_count = null_count
0 commit comments