1

I have defined a function that should add a new column called season to the data frame. The values of season are extracted from the date column:

def season(df):

    df['sum'] = ((df['date'].dt.month) * 100) + df['date'].dt.day

    df['season'] = np.where(df['sum'] > 320 & df['sum'] < 621, 1, np.where(df['sum'] > 620 & df['sum'] < 923, 2, np.where(df['sum'] > 922 & df['sum'] < 1223, 3, 4)))

    df.drop(['sum'], axis=1, inplace=True)

    return df

But when I call this function inside the main code, I get this error message: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Where should be modified?

Thanks.

1 Answer 1

1

Put df['sum'] >320 inside brackets, i.e. (df['sum']>320)&(...).

Or you can use gt and lt: df['sum'].gt(320)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.