相关疑难解决方法(0)

使用Python编辑csv文件时跳过标题

我使用下面引用的代码使用Python编辑csv.代码中调用的函数形式代码的上半部分.

问题:我希望下面引用的代码从第2行开始编辑csv,我希望它排除包含标题的第1行.现在它只在第一行应用函数,我的标题行正在改变.

in_file = open("tmob_notcleaned.csv", "rb")
reader = csv.reader(in_file)
out_file = open("tmob_cleaned.csv", "wb")
writer = csv.writer(out_file)
row = 1
for row in reader:
    row[13] = handle_color(row[10])[1].replace(" - ","").strip()
    row[10] = handle_color(row[10])[0].replace("-","").replace("(","").replace(")","").strip()
    row[14] = handle_gb(row[10])[1].replace("-","").replace(" ","").replace("GB","").strip()
    row[10] = handle_gb(row[10])[0].strip()
    row[9] = handle_oem(row[10])[1].replace("Blackberry","RIM").replace("TMobile","T-Mobile").strip()
    row[15] = handle_addon(row[10])[1].strip()
    row[10] = handle_addon(row[10])[0].replace(" by","").replace("FREE","").strip()
    writer.writerow(row)
in_file.close()    
out_file.close()
Run Code Online (Sandbox Code Playgroud)

我试图通过初始化row变量来解决这个问题,1但它没有用.

请帮我解决这个问题.

python csv python-2.7

185
推荐指数
4
解决办法
22万
查看次数

标签 统计

csv ×1

python ×1

python-2.7 ×1