I have an list of indices from a groupby operation like this:
pd.DataFrame([
{
'group': 'product_1',
'value': 0.2,
},
{
'group': 'product_1',
'value': 0.3,
},
])
idx = (
df.iloc[df
.groupby('group')
['value']
.idxmin(axis=0) # select first occurrence of min error in each group
]
.index
)
I want to convert it to a boolean series/mask like this:
df_2 = df.copy()
df_2['mask'] = False
df_2.loc[idx, 'mask'] = True
which results in:
[True, False]
Is there a more consise way to perform the second (or both) steps?