I'm trying to read in a csv file from the command line and do a few calculations on the columns. However, I'm struggling to skip the first row (Header Row) when the file gets read in.
For example, here is a screenshot of the csv file:
Here is the code I'm using currently:
#!/usr/bin/env python
import sys
import re
import csv
def main(argv):
for row in csv.reader(iter(sys.stdin.readline, "")):
quantity = int(row[3])
price_per_unit = int(row[5])
cum_sum = quantity*price_per_unit
print(row[0]+" "+str(cum_sum)+" "+row[6]+"\t"+"1")
#Note there are two underscores around name and main
if __name__ == "__main__":
main(sys.argv)
From the command line I'm running this:
python problem1.py < orders.csv