python if for 一行语法

 

import pandas as pd
df=pd.DataFrame({"A":[2,3,4,5],"B":[7,9,6,6]})
print(df)
id = [i for i, j in enumerate(df['B']) if j == 6] #if语句是可选项
print(id)

输出结果

   A  B
0  2  7
1  3  9
2  4  6
3  5  6
[2, 3]

 

posted @ 2023-03-14 22:49  yayagogogo  阅读(56)  评论(0编辑  收藏  举报