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

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

python - Using columnar data in for loop

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

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

1 Answer

0 votes
by (71.8m points)
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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...