df_2019Prod_weight[‘Year_max’]=df_2019Prod_weight.groupby([‘COMMODITY_DESC’, ‘CLASS_DESC’,’UNIT_DESC’])[‘YEAR’].transform(max)
idx = df_2019Prod_weight[‘Year_max’]==df_2019Prod_weight[‘YEAR’]
df_2019Prod_weight_1=df_2019Prod_weight[idx]
df_2019Prod_weight[‘Year_max’]=df_2019Prod_weight.groupby([‘COMMODITY_DESC’, ‘CLASS_DESC’,’UNIT_DESC’])[‘YEAR’].transform(max)
idx = df_2019Prod_weight[‘Year_max’]==df_2019Prod_weight[‘YEAR’]
df_2019Prod_weight_1=df_2019Prod_weight[idx]