<div>i wrote a code for extracting information from a csv file into another csv file.<br clear="all"></div><div>it worked well but i have an immediate challenge i can't seem to fix.</div><div>the new file that is created has an row and then an empty row and then a row all through the file. how can i make the empty rows not be part of the file.</div>
<div><br></div><div>here is the code:</div><div><br></div><div>import csv<br><br>reader = csv.reader(open('stateparty.csv'))<br>counter = 1<br>fh = open('stateparty2.csv','w')<br>writer = csv.writer(fh)<br>
for row in reader:<br> if counter == 1:<br> parties_row = row<br> elif counter > 2:<br> for index, column in enumerate(row[1:-1]):<br> if column == "1":<br>
writer.writerow([row[0],parties_row[index+1]])<br> counter += 1 <br>fh.close()<br></div><div><br></div><div><br></div><div>and the output has something like this:</div><div><br></div>
<div><br></div><div>Benue,ACN<br><br>Benue,ANPP<br><br>Benue,APGA<br><br>Benue,CPC<br><br>Benue,PDP<br><br>Kogi,ACN<br><br>Kogi,ADC<br><br>Kogi,ANPP<br><br>Kogi,APGA<br><br>Kogi,CDC<br><br>Kogi,CPC<br><br>Kogi,DPP<br></div>
<div><br></div><div><br></div><div>i am not expecting the spaces in between each line, kindly help with the challenge...<br></div><div><br></div><div>thanks.</div>-- <br>Elegbede Muhammed Oladipupo<br>OCA<br>+2348077682428<br>
+2347042171716<br><a href="http://www.dudupay.com">www.dudupay.com</a><br>Mobile Banking Solutions | Transaction Processing | Enterprise Application Development<br>