user11357465
user11357465

Reputation:

How To Perform Multiple If Statements Across DataFrame Rows?

I want to perform Multiple If Statements but it doesn't seem to work? I would consider using a simple function but I thought .loc was quicker?

df.loc[df.ses1.isnull() & df.ses2 == 6 | 7, 'ses1'] = 4

This executes, but the dataframe does not change? Why?

Upvotes: 0

Views: 26

Answers (1)

Arn
Arn

Reputation: 2015

Because the query that you are making probably returns an empty series (that's my guess). Multiple conditions work according to a specific precedence of operators. Try:

df.loc[df.ses1.isnull() & (df.ses2 == 6) | (df.ses2 == 7), 'ses1'] = 4

Upvotes: 1

Related Questions