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

You’re essentially doing a feature transformation from side-specific labels (left/right) into a binary condition (injured vs uninjured).

Short approach

  1. Combine left/right injury columns

  2. Map any injury → Injured (1)

  3. No injury → Uninjured (0)

import pandas as pd

# example
df = pd.DataFrame({
    "left_injury": [0, 1, 0, 0],
    "right_injury": [0, 0, 1, 0]
})

# create new column
df["injury_status"] = ((df["left_injury"] == 1) | (df["right_injury"] == 1)).astype(int)

If injuries are text-based

df["injury_status"] = df[["left_injury", "right_injury"]]\
    .apply(lambda x: 1 if "injured" in x.values else 0, axis=1)

You’re collapsing multiple related features into a single binary indicator, which simplifies modeling and improves interpretability.

This is common in ML preprocessing when the direction or side is less important than the condition itself.

Be the first to post a comment.

Add a comment