gpt4 book ai didi

python - 使用 csvcut (python) 获取列时如何将文本限定符包含为 none?

转载 作者:太空宇宙 更新时间:2023-11-03 17:39:35 28 4
gpt4 key购买 nike

我有一个 csv 文件,其中包含下面的示例记录,该文件以竖线分隔。

  1. A|B|C|D
  2. E|F|G|H
  3. I|"J"||"K"|L
  4. M|N|O|P

对于上面的示例,当我使用 csvcut 剪切列并将分隔符指定为“|”时我能够获取 1st,3rd,4th row3rd row 不会出现,因为它在双引号内具有某些字段值。如何也使用csvcut

最佳答案

你可以试试这个:

import csv
with open('a.csv', 'rb') as csvfile:
areader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in areader:
print ' '.join(row)

那么你有:

1. A|B|C|D
2. E|F|G|H
3. I|"J"||"K"|L
4. M|N|O|P

不要忘记“b”标志。

关于python - 使用 csvcut (python) 获取列时如何将文本限定符包含为 none?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30774363/

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