detect_nan_for_str_column¶
- pyhelpers.ops.detect_nan_for_str_column(data_frame, column_names=None)[source]¶
Detect if a column with string type contains
NaN
values for a given dataframe.- Parameters:
data_frame (pandas.DataFrame) – A dataframe to be examined.
column_names (collections.abc.Iterable | None) – A sequence of column names to check; if
column_names=None
(default), all columns are checked.
- Returns:
Generator yielding position index of columns that contain
NaN
.- Return type:
Generator
Examples:
>>> from pyhelpers.ops import detect_nan_for_str_column >>> from pyhelpers._cache import example_dataframe >>> dat = example_dataframe() >>> dat Easting Northing City London 530034 180381 Birmingham 406689 286822 Manchester 383819 398052 Leeds 582044 152953 >>> dat.loc['Leeds', 'Latitude'] = None >>> dat Easting Northing City London 530034 180381.0 Birmingham 406689 286822.0 Manchester 383819 398052.0 Leeds 582044 NaN >>> nan_col_pos = detect_nan_for_str_column(data_frame=dat, column_names=None) >>> list(nan_col_pos) [1]