Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to skip the headers when processing a csv file using Python?

$
0
0

I am using below referred code to edit a csv using Python. Functions called in the code form upper part of the code.

Problem: I want the below referred code to start editing the csv from 2nd row, I want it to exclude 1st row which contains headers. Right now it is applying the functions on 1st row only and my header row is getting changed.

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 = 1for 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()

I tried to solve this problem by initializing row variable to 1 but it didn't work.

Please help me in solving this issue.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>