1

The below code snippet containing conditional statements is not working as expected. It's returning all 0s for usage['knozo'] where it should contain 1s as well for some rows. Can someone figure out where am I going wrong in this loop/condition?

for i in range(0,len(usage)):
    for j in range(0,len(knozo)):
        if usage['key_usage'].iloc[i] == knozo['key_knozo'].iloc[j]:
            usage['knozo'] = 1
        else:
            usage['knozo'] = 0
            break
1
  • that means the conditional you have is always false. So Id start with looking at those 2 variables independently to see whats going on. Maybe add a print statement? print("{} == {} => {}".format(a,b,a==b)) where a and b are those 2 condition parameters? Commented Mar 14, 2018 at 16:16

1 Answer 1

1

You could try replacing

if usage['key_usage'].iloc[i] == knozo['key_knozo'].iloc[j]:

with

if usage.at[i, 'key_usage'] == konzo.at[j, 'key_konzo']:

edit: also, doing usage['konzo'] = 0 will fill the entire series with that value, so the last condition you evaluate happens to be 0, and you're filling the entire dataframe. You need to specify which element you want to change.

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.