INNER CODE UNIT · Python
_timedelta_variable_summary_table
aeturrell/skimpy · src/skimpy/__init__.py:536
def _timedelta_variable_summary_table(xf: pd.DataFrame) -> pd.DataFrame:
"""Summarise dataframe columns that have timedelta type. (NB not object type).
Args:
xf (pd.DataFrame): Dataframe with columns of only timedelta types
Returns:
pd.DataFrame: A dataframe of summary statistics, with a number of rows
determined by number of columns of xf
"""
count_nans_vec = xf.isna().sum()
# NB: timedelta doesn't play nicely with rounding
data_dict = {
MISSING_COL: count_nans_vec,
COMPLETE_COL: 100 * count_nans_vec / xf.shape[0],
NUM_COL_MEAN: xf.mean().dt.floor("s"),
"median": xf.min().dt.floor("s"),
"max": xf.max().dt.ceil("s"),