datetime_ops

datetime_ops contains a variety of utility functions to help with processing datetime objects

nesta_ds_utils.cleaning.datetime_ops.parse_date_string(date_string: str, format: Union[str, list] = '%Y-%m-%d', error_value: Union[float, str] = nan) datetime[source]

parses a date string into a datetime object

Parameters:
  • date_string (str) – string describing a date.

  • format (str or list, optional) – date format or list of possible date formats. Defaults to “%Y-%m-%d”.

  • documentation (For additional date format options refer to datetime) –

  • error_value (float or str, optional) – value to use for null or improperly formatted values. Defaults to numpy.nan.

Returns:

date in datetime format if date_string matches date format, otherwise returns None.

Return type:

datetime.datetime

nesta_ds_utils.cleaning.datetime_ops.get_date_part(date: datetime, date_part: str = 'year') int[source]

extracts a specified date part from a datetime object

Parameters:
  • date (datetime.datetime) – datetime object

  • date_part (str, optional) – part to extract, options are year, month, or day. Defaults to “year”.

Returns:

date part as integer

Return type:

int