How to read one single line of csv data in Python?

后端 未结 7 1387
终归单人心
终归单人心 2020-11-28 05:04

There is a lot of examples of reading csv data using python, like this one:

import csv
with open(\'some.csv\', newline=\'\') as f:
  reader = csv.reader(f)
          


        
7条回答
  •  天涯浪人
    2020-11-28 05:38

    To print a range of line, in this case from line 4 to 7

    import csv
    
    with open('california_housing_test.csv') as csv_file:
        data = csv.reader(csv_file)
        for row in list(data)[4:7]:
            print(row)
    

提交回复
热议问题