0

I'm making a sublist of every row inside a csv file but i'm getting a single list back

wines_list = []

for row in wines:
    wines_list.append(row)

print(wines_list)

This 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']

But i wan't it to append all values to sublist, and append that to wines_list

So i want wines_list to become something like:

[[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]
Wesley van S
  • 69
  • 1
  • 12
  • https://stackoverflow.com/questions/41585078/how-do-i-read-and-write-csv-files-with-python – Zonyl Apr 02 '19 at 14:29

1 Answers1

0

easiest way is something like this

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

print(wines_list)

then wines_list will be a list of lists

SuperStew
  • 2,857
  • 2
  • 15
  • 27