我有一个 7 列 20 行的 CSV 文件(students_temp.csv):
Name,Age,Gender,Varsity,GPA,Town,State
John,18,Male,yes,3.2,Tacoma,WA
Tyler,18,Male,yes,2.9,Tacoma,WA
Jane,17,Jane,yes,3.5,Tacoma,WA
Michelle,18,Female,no,3.1,Tacoma,WA
Jamie,17,Male,no,2.6,Tacoma,WA
Robert,17,Male,yes,4.0,Tacoma,WA
Danielle,18,Female,no,3.0,Tacoma,WA
Dustin,18,Male,no,3.2,Tacoma,WA
Angela,16,Female,no,2.9,Tacoma,WA
Barbara,17,Female,yes,3.5,Tacoma,WA
Megan,18,Female,no,3.4,Tacoma,WA
Michael,18,Male,yes,3.0,Tacoma,WA
Craig,17,Male,no,3.1,Tacoma,WA
Jackson,18,Male,no,2.8,Tacoma,WA
Bill,18,Male,yes,3.2,Tacoma,WA
Matthew,17,Male,yes,3.0,Tacoma,WA
Karen,16,Female,no,3.4,Tacoma,WA
Sarah,17,Female,yes,3.2,Tacoma,WA
Charles,18,Male,no,3.5,Tacoma,WA
我想读取文件,解析 Varsity 列并将该列中的所有内容更改为大写,然后将包含更改的整个 CSV 文件写入新的 CSV 文件 (students.csv)。
这是我到目前为止所拥有的,但它并没有遍历整个专栏:
import csv
input_file = csv.DictReader(open('students_temp.csv', 'rb'))
for row in input_file:
varsity_col = str(row['Varsity'])
varsity_col.upper()
print varsity_col.upper()