I want to give priority on Multiple columns and select row based on priority
I wanted to select ID\'s with RC priority in Category Column and Pending Priority in Sta
Convert columns to ordered categoricals with set priority by passing list to categories
parameter, then sorting by 3 columns by DataFrame.sort_values and last remove duplicates with DataFrame.drop_duplicates:
df['Category'] = pd.Categorical(df['Category'], ordered=True, categories=['GC','RC'])
df['Status'] = pd.Categorical(df['Status'], ordered=True, categories=['Resolved','Pending'])
df = df.sort_values(['ID','Category','Status']).drop_duplicates('ID', keep='last')
print (df)
ID Category Status Date
1 1 RC Resolved 05-10-2016
3 2 RC Pending 09-08-2016
6 3 RC Pending 13-05-2019
7 4 GC Pending 10-06-2018