0

I have a dataset that looks like this:

VendorAccount   FiscalPeriod    LCC
729616,             1,          False
729616,             2,          False
0,                  2,          False
1,                  4,          False

I attempted to use this line:

df['LCC'][(df['VendorAccount'] == 729616) & df['FiscalPeriod'] >1] = True

to make it look like this:

VendorAccount   FiscalPeriod    LCC
729616,             1,          False
729616,             2,          True
0,                  2,          False
1,                  4,          False

The script runs but no changes are being made. Can anyone advise me on where I am going wrong?

1 Answer 1

1

& operator has higher precedence than >, hence your original code is equivalent to this:

df['LCC'][((df['VendorAccount'] == 729616) & df['FiscalPeriod']) > 1] = True

To update the dataframe correctly you should use the following code instead:

df['LCC'][(df['VendorAccount'] == 729616) & (df['FiscalPeriod'] > 1)] = True
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.