Adding and multiplying higher values based on different columns of a dataframe
So, from what I understand from the problem, you want create a Score column, whereby, typically:
$Score = A \times B \times C \times D \times E$
If ID == VID and the value in QID for that entry is unique in the whole data frame, then $E = max(E)$.
For this, I would create additional columns which check for these conditions before making the score column. Therefore, I would recommend this:
import numpy as np
import pandas as pd

# unique QID
QID_counts = df.groupby(&quot;QID&quot;).size().reset_index()
QID_counts.columns = [&quot;QID&quot;, &quot;QID_count&quot;]

df = pd.merge(left = df, right = QID_count, on = &quot;QID&quot;)

# checking if IDs are equal to VID
df[&quot;ID_VID&quot;] = df[df[&quot;ID&quot;] == df[&quot;VID&quot;]]
df[&quot;Unique_QID&quot;] = df[df[&quot;QID_count&quot;] == 1]

# checking if both conditions are met
df[&quot;Max E&quot;] = df[&quot;ID_VID&quot;] &amp; df[&quot;Unique_QID&quot;]
df[&quot;Max E&quot;] = df[&quot;Max E&quot;].astype(int)
# obtaining indices 
max_E_idxs = df[df[&quot;Max E&quot;] == 1].index

# updating E to suit conditions
df[&quot;Score_E&quot;] = df[&quot;E&quot;]
df.loc[max_E_idxs,&quot;Score_E&quot;] = np.max(df[&quot;E&quot;])

# creating score
df[&quot;Score&quot;] = df[&quot;A&quot;] * df[&quot;B&quot;] * df[&quot;C&quot;] * df[&quot;D&quot;] * df[&quot;Score_E&quot;]
```