gpt4 book ai didi

python - 从 CSV 文件中去除空格

转载 作者:IT老高 更新时间:2023-10-28 22:20:24 37 4
gpt4 key购买 nike

我需要从我读取的 CSV 文件中删除空格

import csv

aList=[]
with open(self.filename, 'r') as f:
reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
for row in reader:
aList.append(row)
# I need to strip the extra white space from each string in the row
return(aList)

最佳答案

还有嵌入的格式化参数:skipinitialspace(默认为false) http://docs.python.org/2/library/csv.html#csv-fmt-params

aList=[]
with open(self.filename, 'r') as f:
reader = csv.reader(f, skipinitialspace=False,delimiter=',', quoting=csv.QUOTE_NONE)
for row in reader:
aList.append(row)
return(aList)

关于python - 从 CSV 文件中去除空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14885908/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com