2

i want ro remove specific lines from the following csv file :

"Title.XP PoseRank" 

1VDV-constatomGlu-final-NoGluWat. 

1VDV-constatomGlu-final-NoGluWat. 

P6470-Usha.1 

P6470-Usha.2 

P6470-Usha.3 

P6470-Usha.4 

P6470-Usha.5 

P6515-Usha.1 

P6515-Usha.2 

P6517.1 

P6517.2 

P6517.3 

P6517.4 

P6517.5 

P6553-Usha.1 

P6553-Usha.2 

P6553-Usha.3 

i want to remove the lines that begin with 1VDV-constatomGlu-final-NoGluWat.

2
  • 3
    Is it just me, or is that a comma separated value file without any commas or separation? Commented Jul 12, 2010 at 6:27
  • This particular task would probably be easier to accomplish with sed or awk. (Although it's not a hard thing to do in any language) Commented Jul 12, 2010 at 6:40

1 Answer 1

2

The right solution is to use csv parser(i didn't test this code):


writer = csv.writer(open('corrected.csv'))
for row in csv.reader('myfile.csv'):
    if not row[0].startswith('1VDV-constatomGlu-final-NoGluWat.'):
        writer.writerow(row)
writer.close()

You can use also regular expression or some string manipulations but there is the risk that after your transformations the file will be no longer in csv format

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.