RE: How can I transform left/right injury data into injured vs uninjured categories in Python?

You can simplify this by mapping all injury-specific columns (left/right) into a single binary flag: injured vs uninjured.

Basic idea

If any injury column has a value → mark as Injured (1)
If all are empty/zero → Uninjured (0)

Example in Python (Pandas)

import pandas as pd

# sample columns
injury_cols = ['left_injury', 'right_injury']

# create new column
df['injured'] = df[injury_cols].notna().any(axis=1).astype(int)

If values are 0/1 instead of NaN

df['injured'] = (df[injury_cols].sum(axis=1) > 0).astype(int)

If you want labels instead of 0/1

df['injured_label'] = df['injured'].map({1: 'Injured', 0: 'Uninjured'})

Optional: Drop original columns

df = df.drop(columns=injury_cols)

You’re converting multiple condition-specific features into a single target variable, which is often cleaner for modeling and analysis.

If your dataset has more complexity (severity, multiple injuries, time-based data), this can be extended into multi-class or scoring instead of just binary.

Be the first to post a comment.

Add a comment