Yes_par_row
Yes_par_row

Reputation: 79

How to remove single quotes and double quotes in csv file without pandas

I am printing the each data in csv file.While reading it was showing SingleQuotes and double quotes.I need to remove if it has any quotations in file

Sample csv file:

Name,Age,Year of Service,Membership,Audit,Leaves,CTC
Rob,'54',32,'Gold',N,5,"335000.50"

Code :

with open('output.csv','r') as i:
    for row in csv.reader(i):
        for columns in row:
            print(columns.replace('"',''))

above code will remove double quotes and print values without double quotes. i also need to remove single quote as well.

Request your help on this

Upvotes: 0

Views: 1030

Answers (1)

Adrian Klaver
Adrian Klaver

Reputation: 19590

Use strip().

with open('output.csv','r') as i:
  for row in csv.reader(i):
     for columns in row:
        print(columns.replace('"','').strip("'"))

Rob
54
32
Gold
N
5
335000.50

Upvotes: 1

Related Questions