[Python] Pandas - Case when & default in pandas

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have the below case statement in python,

    pd_df['difficulty'] = 'Unknown'
    pd_df['difficulty'][(pd_df['Time']<30) & (pd_df['Time']>0)] = 'Easy'
    pd_df['difficulty'][(pd_df['Time']>=30) & (pd_df['Time']<=60)] = 'Medium'
    pd_df['difficulty'][pd_df['Time']>60] = 'Hard'


    But when I run the code, it throws an error.

    A value is trying to be set on a copy of a slice from a DataFrame

    Continue reading...

Compartilhe esta Página