[英]How to replace value using python format function?
我有这些数据,我想编写一个Python程序来替换csv中的值。 我的csv具有以下数据:
name,studentno
abc,student1
xyz,student2
rty,student3
wer,student4
码:
mystring= "Test {} value : {}"
print (my_string.format(column1value from csv, column2value from csv))
如何遍历csv并放置列值? 请帮忙。 我需要如下所示的输出。 输出:
Test abc value : student1
Test xyz value : student2
Test rty value : student3
Test wer value : student4
import csv
mystring= "Test {} value : {}"
with open('yourfil.csv', 'rb') as csvfile:
csv_reader = csv.reader(csvfile, delimiter=',')
for row in csv_reader:
mystring.format(row[0], row[1])
我认为这应该有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.