import csv
with open ("ann.csv", "rb") as csvfile:
reader = csv.reader(csvfile)
reader.next() # Skip the header row
collected = []
for row in reader:
collected.append(row[0])
print ",".join(collected)
with open ("ann.csv", "rb") as annotate:
output = []
next(annotate) # next will advanced the file pointer to next line
for col in annotate:
output.append(col.lower().split(",")[0])
print ",".join(output)
result = ''
with open ("ann.csv", "rb") as annotate:
for col in annotate:
ann = col.lower().split(",")
# add first element of every line to one string and separate them by comma
result = result + ann[0] + ','
print result
首先,在Python中有^{} module -使用它。
其次,您要遍历行,因此使用
col
作为变量名有点混乱。第三,收集列表中的项目并使用
.join()
打印:像这样试试:
然后试试这个:
相关问题 更多 >
编程相关推荐