0

Let's consider a dataframe like this:

(index)    condition    number
0          'increase'   1
1          'do-nothing' 1

I'd like to increment the elements in the number column if the condition element in the same row is equal to 'increase'. In principle, I thought about something similar:

# non-working example
df['number'] = df['number'].apply(lambda x: x+=1 if x['condition'] == 'increase' else x)

This example of course does not work. Is there an efficient method to do it?

1 Answer 1

1

I think you're looking for:

df.loc[df['condition'] == 'increase', 'number'] += 1
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.