0
我有以下列格式与标头csv文件:检索列的标题,如果它有一个特定值
column1
,column2
,column3
True
,False
,False
False
,True
,True
在python中,我想打印列名称,如果其值为True
(column1
,然后对于下一行column2
和column3
)。在下面的代码中,它打印每一列。
with open(reportOut, 'r') as f:
reader = csv.reader(f, skipinitialspace=True)
header = next(reader)
for row in reader:
if 'True' in row:
print(header)