Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to create an And statement in my for loop. There is a data frame that I have under "b". There are two columns of the data frame that I isolated into their respective lists (cdr3_length and heavy_percent).

I'm trying to create a for loop where the it parses through b and adds all data where the cdr3_length > 15 and heavy_percent < 88 to a new list "candidates".

cdr3_length=marv["heavy_cdr3_aa_length"]
cdr3_length.head()
heavy_percent=marv["heavy_percent_id"]
heavy_percent.head()

cnt_=0
candidates=[]
for i in range(0, len(b)):
    if (cdr3_length(b[i]) > 15 & heavy_percent(b[i]) < 88
    candidates.append(b[i])

cnt_+=1

I am getting a syntax error in the if statement line, but I can't find it. I appreciate any hep given!

question from:https://stackoverflow.com/questions/65894384/using-columnar-data-in-for-loop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
163 views
Welcome To Ask or Share your Answers For Others

1 Answer

if (cdr3_length(b[i]) > 15 & heavy_percent(b[i]) < 88
candidates.append(b[i])

->

if (cdr3_length(b[i]) > 15) and (heavy_percent(b[i]) < 88):
    candidates.append(b[i])

python uses indentation to form blocks of code, so you should watch this closely. Also you may want to visit python.org an read its awesome beginners guide. While both typing an syntax are both relaxed in this language they still demand respect


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...