Python Excel 如果条件为真打印下一行 t+1
Python Excel if a condition is true print next line t+1
更新:
我希望 python 在满足条件时将 excel 文件中的 t+1 之类的下一行打印到 python 输出 window 中。我认为问题出在这部分代码
print "FA",row[0], ','.join(row[1:])
这会打印今天我需要 python 打印第二天 (t+1)
我试过了print "FA",row[0], ','.join(row[1:]).nextline()
但这不起作用
例如
假设 excel 文件有
35F 1,0,1,0,1,1,1
66F 1,0,1,0,0,0,0
35F 1,0,1,0,1,1,1<-- at this moment python prints this part
66F 1,0,1,0,0,0,0<--- **But I want python to print this {66F 1,0,1,0,0,0,0} this is the t+1**
此外,这里是完整的代码
import csv
with open('2015weather.csv', 'r') as file1:
val = list(csv.reader(file1))[3]
with open('FAsince1900.csv', 'r') as file2:
reader = csv.reader(file2)
reader.next() # this skips the first row of the file
# this iteration will start from the second row of file2.csv
for row in reader:
if row[1:] == val:
print print "FA",row[0], ','.join(row[1:])
更新 2:
这样的事情怎么样:
conditionMet = False
for row in reader:
if conditionMet == True:
print "FA",row[0], ','.join(row[1:])
conditionMet = False # or break if you know you only need at most one line
if row[1:] == val:
conditionMet = True
更新:
我希望 python 在满足条件时将 excel 文件中的 t+1 之类的下一行打印到 python 输出 window 中。我认为问题出在这部分代码
print "FA",row[0], ','.join(row[1:])
这会打印今天我需要 python 打印第二天 (t+1)
我试过了print "FA",row[0], ','.join(row[1:]).nextline()
但这不起作用
例如 假设 excel 文件有
35F 1,0,1,0,1,1,1
66F 1,0,1,0,0,0,0
35F 1,0,1,0,1,1,1<-- at this moment python prints this part
66F 1,0,1,0,0,0,0<--- **But I want python to print this {66F 1,0,1,0,0,0,0} this is the t+1**
此外,这里是完整的代码
import csv
with open('2015weather.csv', 'r') as file1:
val = list(csv.reader(file1))[3]
with open('FAsince1900.csv', 'r') as file2:
reader = csv.reader(file2)
reader.next() # this skips the first row of the file
# this iteration will start from the second row of file2.csv
for row in reader:
if row[1:] == val:
print print "FA",row[0], ','.join(row[1:])
更新 2:
这样的事情怎么样:
conditionMet = False
for row in reader:
if conditionMet == True:
print "FA",row[0], ','.join(row[1:])
conditionMet = False # or break if you know you only need at most one line
if row[1:] == val:
conditionMet = True