0

Background:
The following function takes a pandas DataFrame and renames it exceptions_df whilst applying 2x conditions to it.

Function:

def ownership_exception_report():
    df = ownership_qc()
    exceptions_df = df[df['Entity ID %'] != 100.00]
    exceptions_df = df[df['Account # %'] != 100.00]
    return exceptions_df

My problem:
Whilst my code works fine, I wonder if there is a simple and more eloquent way to apply 2x conditions to a DataFrame and resave it? At the moment I am simply resaving the exceptions_df twice and it seems rather messy. Or perhaps I am wrong, and this is the correct way to apply conditions to a DataFrame?

1 Answer 1

3
def ownership_exception_report():
    df = ownership_qc()
    return df[(df['Entity ID %'] != 100.00) & (df['Account # %'] != 100.00)]

Or:

def ownership_exception_report():
    df = ownership_qc()
    return df[df['Entity ID %'].ne(100.00) & df['Account # %'].ne(100.00)]

Both will return a copy of df with only the rows where Entity ID % is 100 AND Account # % is 100.

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.