csv=csv=b''.join(csv).split(b'\n')
for index,row in enumerate(csv):
  row=re.split(b''',(?=(?:[^'"]|'[^']*'|"[^"]*")*$)''',row)
  for records in row:
      print(records)

when it printing the records ,for the 3rd element it prints with ""i need to ignore this doubles quotes.

3 个评论
你不使用pandas有什么原因吗?
使用csv的内置模块或pandas.read_csv的第三方模块功能来读取文件
是的,由于第三方的预防措施
python
string
csv
Stay cool
Stay cool
发布于 2022-07-27
2 个回答
noah1400
noah1400
发布于 2022-07-27
已采纳
0 人赞同

I think this should do it:

records = records.replace("\"","")

Using pandas.read_csv is better for working with csv files

import pandas as pd
csv = pd.read_csv('data.csv', delimiter=',', names=['x', 'y', 'z'])
# iterate over the dataframe
for index, row in csv.iterrows():
    print(row['x'], row['y'], row['z'])

假设data.csv的内容是这样的

Mp4,Mp3,"1234554"

The Output would look like this:

Mp4 Mp3 1234554

如果你的csv文件包括列名,如

file_type1,file_type2,size
mp4,mp3,"1234554"

如果你读入csv文件,只需删除names参数。

csv = pd.read_csv('data.csv', delimiter=',')
print(csv)

Then the Output would look like this:

  file_type1 file_type2     size
0        mp4        mp3  1234554