[英]python if condition for the first line of a table
I have this table. 我有这张桌子。 This table is made through a loop.
该表是通过循环创建的。
for line in res.split('\n')[1:4]:
list=line.split()
Results this table 结果表
ID Prefix-list
1 | ['ip', 'prefix-list', '2603', 'permit', '1.2.4.0/24']
2 | ['ip', 'prefix-list', '2603', 'permit', '2.2.4.0/24']
3 | ['ip', 'prefix-list', '2603', 'permit', '3.2.4.0/24']
4 | ['ip', 'prefix-list', '2603', 'permit', '4.2.4.0/24']
I want to use a another loop but i dont want to iterate through all the rows. 我想使用另一个循环,但是我不想遍历所有行。 so lets say if the first item of the row[0] is == "ip" then print all the rows.
因此可以说,如果row [0]的第一项是==“ ip”,则打印所有行。
for item in table1:
if item[0] from the first row == "ip":
print(item)
Any Idea? 任何想法?
this will work: 这将工作:
if table1.loc[0,'Prefix-List'][0] == "ip":
print table1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.