"""
for (discussion, turn, du_id), gold_group in gold_df.groupby(['discussion', "turn", "du_id"]):
# find the corresponding predicted segments for this discussion and turn
pred_group = pred_df[
(pred_df['discussion'] == discussion) &
(pred_df["turn"] == turn) & (pred_df["du_id"] == du_id)
]
"""
raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Assistant
The error you're seeing:
cssCopyEditValueError: The truth value of a Series is ambiguous.
Use a.empty, a.bool(), a.item(), a.any() or a.all().
means that somewhere in your boolean expressions, you're doing something that results in a Pandas Series of booleans, but Python expects a single True or False — not a whole series.
From your code:
pythonCopyEditfor (discussion, turn, du_id), gold_group in gold_df.groupby(['discussion', "turn", "du_id"]):
# find the corresponding predicted segments for this discussion and turn
pred_group = pred_df[
(pred_df['discussion'] == discussion) &
(pred_df["turn"] == turn) & (pred_df["du_id"] == du_id)
]
This part looks fine if:
pred_df['discussion'], pred_df['turn'], and pred_df['du_id'] are standard pandas Series of simple types (like strings, ints).
Likely Cause
The issue likely comes from one of these columns ('discussion', 'turn', or 'du_id') containing non-scalar values (e.g. a list or array), which causes == to return a Series instead of a scalar comparison. Then when you try to use &, it can't resolve ambiguity between multiple boolean values.
How to Debug
Add a debug line like this before the filtering:
pythonCopyEditprint(type(discussion), discussion)
print(type(turn), turn)
print(type(du_id), du_id)
print(pred_df[['discussion', 'turn', 'du_id']].dtypes)
Also check:
pythonCopyEditprint(pred_df['discussion'].iloc[0]) # or turn / du_id
Fixes
If any of discussion, turn, or du_id is accidentally a list or numpy array, cast it to a scalar value:
Example:
pythonCopyEditif isinstance(turn, np.ndarray):
turn = turn.item()
Or check how your data is being read in — sometimes groupby keys can become numpy arrays if the column contains non-scalar values.
Alternative Debugging Trick
Try breaking down the condition like this:
pythonCopyEditcond1 = pred_df['discussion'] == discussion
cond2 = pred_df['turn'] == turn
cond3 = pred_df['du_id'] == du_id
print(cond1.head(), cond2.head(), cond3.head())
Now combine:
pred_group = pred_df[cond1 & cond2 & cond3]
If any of those prints show something weird (like a Series of arrays or ValueError), you'll know exactly where the problem lies.
Let me know what the types or values are if you want help narrowing it down.