detect_nan_for_str_column

pyhelpers.ops.detect_nan_for_str_column(data_frame, column_names=None)[source]

Detect if a str type column contains NaN when reading csv files.

Parameters:
  • data_frame (pandas.DataFrame) – a data frame to be examined

  • column_names (None | collections.abc.Iterable) – a sequence of column names, if None (default), all columns

Returns:

position index of the column that contains NaN

Return type:

Generator[Iterable]

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]