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

A simple way to handle this is to convert the left/right injury information into a single binary category:

  • Injured → if either left or right injury exists

  • Uninjured → if neither exists

Using Pandas, you can do it like this:

import pandas as pd

injury_cols = ['left_injury', 'right_injury']

df['injury_status'] = df[injury_cols].notna().any(axis=1)
df['injury_status'] = df['injury_status'].map({True: 'Injured', False: 'Uninjured'})

If your columns use 0 and 1 values instead of nulls:

df['injury_status'] = (
    df[['left_injury', 'right_injury']].sum(axis=1) > 0
).map({True: 'Injured', False: 'Uninjured'})

This approach is useful when simplifying features for classification models or creating cleaner categories for analysis.

Be the first to post a comment.

Add a comment