Python import csv to list

后端 未结 13 1275
后悔当初
后悔当初 2020-11-22 06:15

I have a CSV file with about 2000 records.

Each record has a string, and a category to it:

This is the firs         


        
13条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 07:00

    You can use the list() function to convert csv reader object to list

    import csv
    
    with open('input.csv') as csv_file:
        reader = csv.reader(csv_file, delimiter=',')
        rows = list(reader)
        print(rows)
    

提交回复
热议问题