初始Dataframe:
Position
Flag Open Close Position
0 No None None 100
1 No None None 0
2 No None None 100
3 No None None 0
4 No None None 0
5 No None None 0
6 No None None 0
筛选:
Temp=Position[(Position.Flag=='No')&(Position.Position>0)]
Temp
Flag Open Close Position
0 No None None 100
2 No None None 100
1.按行遍历迭代成元组
for row in Temp.itertuples():
print(row)
[Out]:
Pandas(Index=0, Flag='No', Open=None, Close=None, Position=100)
Pandas(Index=2, Flag='No', Open=None, Close=None, Position=100)
访问:
getattr(row,'Index')
Out[31]: 2
getattr(row,'Position')
Out[27]: 100
2.按行遍历迭代成(index,Series)对
fo