我如何制作每个 CSV 行的子列表并将该子列表放入列表中

How do i make a sublist of every CSV row and put that sublist inside a list

我正在为 csv 文件中的每一行制作一个子列表,但我得到的是一个列表

wines_list = []

for row in wines:
    wines_list.append(row)

print(wines_list)

这个returns:

['id', 'country', 'description', 'designation', 'points', 'price', 
'province', 'taster_name', 'title', 'variety', 'winery', 'fixed acidity', 
'volatile acidity', 'citric acid', 'residual sugar', 'chlorides', 'free 
sulfur dioxide', 'total sulfur dioxide', 'density', 'pH', 'sulphates', 
'alcohol']

但我不想将所有值附加到子列表,并将其附加到 wines_list

所以我希望 wines_list 变成这样的:

[[1, 'netherlands', 'description of the wine', 'designation', 'points', 'price', 
'province', 'taster_name', 'title', 'variety', 'winery', 'fixed acidity', 
'volatile acidity', 'citric acid', 'residual sugar', 'chlorides', 'free 
sulfur dioxide', 'total sulfur dioxide', 'density', 'pH', 'sulphates', 
'alcohol'], ANOTHER SUB LIST HERE]

最简单的方法是这样的

import csv
pathtocsv='path/to/file'
with open(pathtocsv,'r') as cfile:
    creader=csv.reader(cfile,delimiter=',')
    wines_list=list(creader)

print(wines_list)

然后wines_list将是列表的列表