def set_n_roles_per_predicate(df: pd.DataFrame) -> pd.DataFrame: # per predicate, count roles joint from all workers df['no_roles'] = df.groupby('key').wh.transform( lambda x: utils.is_empty_string_series(x).sum()) df['num_rows'] = df.groupby('key').wh.transform(pd.Series.count) df['n_roles'] = df.apply(lambda r: r['num_rows'] - r['no_roles'], axis=1) df = df.drop(['num_rows'], axis=1) return df
def filter_non_questions(annot_df: pd.DataFrame) -> pd.DataFrame: """ Return subset of `annot_df` with rows that corresponds to an empty question (which are either not-verbal or marked with "no-QA-applicable")""" from qanom import utils with_q = annot_df[utils.is_empty_string_series(annot_df.question)] return with_q
def filter_questions(annot_df: pd.DataFrame) -> pd.DataFrame: """ Return subset of `annot_df` with rows that corresponds to a non-empty question """ with_q = annot_df[~utils.is_empty_string_series(annot_df.question)] return with_q