Calculate percentage based on dummy variable in Pandas
I think the better way is to use groupby. It looks more logical and "natural":

df = pd.DataFrame({
    'Product': ['A', 'B', 'B', 'C', 'D', 'D'],
    'Qty': [10, 15, 5, 5, 5, 20],
    'Dummy': [0, 0, 1, 0, 0, 1]
})

# Create new column = Dummy*Qty
df['DQty'] = df['Dummy'] * df['Qty']

# Groupby df by 'Product' and summarize columns
df2 = df.groupby('Product').sum()

# Create new column equal to percentage of the total quantities
df2['Q'] = df2['DQty'] / df2['Qty']

# Drop unnecessary columns
df2 = df2.drop(columns=['Dummy', 'Qty', 'DQty'])

# Drop rows equal to zero
df2 = df2.loc[df2['Q'] != 0]
df2


The result is:

        Q
Product     
B       0.25
D       0.80