This code works: cohort = r'priority' result2025 = df.groupby([cohort],as_index=False).agg({'resolvetime': ['count','mean']}) and this code works cohort = r'impactedservice' result2025 = df.groupby([cohort],as_index=False).agg({'resolvetime': ['count','mean']}) and this code works result2025 = df.groupby(['impactedservice','priority'],as_index=False).agg({'resolvetime': ['count','mean']}) but what is not working for me is defining the cohort variable to be cohort = r'impactedservice,priority' # a double-cohort result2025 = df.groupby([cohort],as_index=False).agg({'resolvetime': ['count','mean']}) That gives error: KeyError: 'impactedservice,priority' How to properly define the cohort variable in this case? Continue reading...