-1

I have a quite simple command in Python like:

for i in range(len(qr2)):
    if qr2.iloc[i]['Linkage'] == 'Leading'\
        or qr2.iloc[i]['CreatedBy'] == 'Paula'\
    and qr2.iloc[i]['Book'] == 'A' 'B' 'C' 'D' 'E':
         qr_os = qr_os.append(qr2.iloc[i],ignore_index=True)

I am able to receive the rows in Excel which have "Leading" linkage but I am unable to have in the same spreadsheet the rows which have both Paula and Book as A or B or C or D or E.

Anyone able to help? :)

  • 2
    What are you hoping that *qr2.iloc[i]['Book'] == 'A' 'B' 'C' 'D' 'E'* will do? Do you realise that that's equivalent to *qr2.iloc[i]['Book'] == 'ABCDE'* ? – Albert Winestein May 30 '22 at 14:27
  • 1
    You want to use `qr2.iloc[i]['Book'] in {'A', 'B', 'C', 'D', 'E'}` – Matthias May 30 '22 at 14:32
  • You probably want `and qr2.iloc[i]['Book'] in {'A', 'B', 'C', 'D', 'E'}:`, but we need more info about what you expect to happen. Maybe some truncated input and expected output. – Michael Ruth May 30 '22 at 14:32
  • I wish that it will show those createdBy Paula that have book either A or B or C or D or E. Those are 5 completely different books. The spript is suppose to filter one Excel spreadsheet and put those rows in a different spreadsheet. It works, the only issue is how to create if that will 2 conditions. 1. Rows has Leading and 2. Rows have both Paula and one of the book – Paula Ciesielska May 30 '22 at 14:35
  • Thank you all very much for the help! It worked :) – Paula Ciesielska May 30 '22 at 14:38
  • @khelwood: The supposed duplicate is to a different problem. *This* question is how to test a single variable for equality to multiple variables. – martineau May 30 '22 at 14:57
  • @martineau It is the canonical explanation for how to compare a *thing* against multiple *things*. – khelwood May 30 '22 at 16:02

0 Answers0