gnanesh / utils.py
gnaneshwar18's picture
commit
65e3bf9 verified
raw
history blame contribute delete
522 Bytes
# utils.py
import pandas as pd
from typing import List, Dict
def add_predictions_to_df(df: pd.DataFrame, preds: List[Dict]) -> pd.DataFrame:
"""
Given a DataFrame with 'review' and a list of predictions (dicts with label,score),
attach prediction columns and return new DataFrame.
"""
df = df.copy()
labels = [p.get('label', '') for p in preds]
scores = [float(p.get('score', 0.0)) for p in preds]
df['prediction'] = labels
df['prediction_score'] = scores
return df