Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.
#!/usr/bin/python import csv fin = open('rawData.csv', 'rb') source = csv.reader(fin, quoting=csv.QUOTE_NONNUMERIC) fout_hr = open('hr_sorted.csv', 'wb') hr_writer = csv.writer(fout_hr, quoting=csv.QUOTE_NONNUMERIC) fout_min = open('min_sorted.csv', 'wb') min_writer = csv.writer(fout_min, quoting=csv.QUOTE_NONNUMERIC) status = 0 # wait for the header header = None # collecting header lines of the section writer = None # reference to the wanted output writer for row in source: if status == 0: # wait a section header rows if row == 'Point Name:': header = [ row[1:] ] # the list with the info from the first header row status = 1 else: continue elif status == 1: # collecting some header rows if row == '1 Minutes': header.append(row) writer = min_writer elif row == '60 Minutes': header.append(row) writer = hr_writer elif row == 'Date Range': pass # Ignore this header row. elif row == 'Report Timings:': # Ignore this header row. Do output the collected header. for r in header: writer.writerow(r) status = 2 # Get ready for for the value rows. elif status == 2: # collecting the values if len(row) == 4: # detect the row with values writer.writerow(row[0:3]) # output the first three columns only else: writer.writerow(['']) # separator status = 0 # wait for another section else: print 'Unexpected status', status fout_hr.close() fout_min.close()
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.