read specific line in csv file , python

后端 未结 2 1006
春和景丽
春和景丽 2021-01-19 15:06

In an CSV file with python we can read all the file line by line or row by row , I want to read specific line (line number 24 example ) without reading all the

2条回答
  •  误落风尘
    2021-01-19 15:38

    Alternatively you can leverage the nrows and skiprows argument in pandas

    line_number = 30
    pd.read_csv('big.csv.gz', sep = "\t", nrows = 1, skiprows = line_number - 1)
    

    remember skiprows can be a list so if you need the header use

    pd.read_csv('big.csv.gz', sep = "\t", nrows = 1, skiprows = list(range(1, line_number - 1)))
    

提交回复
热议问题