【发布时间】:2019-03-02 14:55:37
【问题描述】:
我有这些数据,我想编写一个 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
【问题讨论】:
-
“my_string.format(column1value from csv, column2value from csv)”真的是你唯一的代码尝试吗?这看起来不像是有效的 python 语法...
-
尝试弄清楚如何遍历 csv 的行并打印每一列的值。一旦你能做到这一点,你的任务就很容易了。不过,恐怕我们不会指导您如何编写
for循环或打开文件。
标签: python python-3.x pandas loops string.format