[英]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我正在打印 csv 文件中的每个数据。读取时显示单引号和双引号。如果文件中有任何引号,我需要删除
Sample csv file: csv 文件示例:
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请求您的帮助
Use strip()
.使用
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.