[英]How to remove single quotes and double quotes in csv file without pandas
我正在打印 csv 文件中的每個數據。讀取時顯示單引號和雙引號。如果文件中有任何引號,我需要刪除
csv 文件示例:
Name,Age,Year of Service,Membership,Audit,Leaves,CTC
Rob,'54',32,'Gold',N,5,"335000.50"
代碼:
with open('output.csv','r') as i:
for row in csv.reader(i):
for columns in row:
print(columns.replace('"',''))
上面的代碼將刪除雙引號並打印沒有雙引號的值。 我還需要刪除單引號。
請求您的幫助
使用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.