How to find specific row in Python CSV module

后端 未结 4 1524
慢半拍i
慢半拍i 2020-12-21 12:21

I need to find the third row from column 4 to the end of the a CSV file. How would I do that? I know I can find the values from the 4th column on with row[3] but how do

4条回答
  •  自闭症患者
    2020-12-21 12:54

    This one is a very basic code that will do the job and you can easily make a function out of it.

    import csv
    
    target_row = 3
    target_col = 4
    
    with open('yourfile.csv', 'rb') as csvfile:
        reader = csv.reader(csvfile)
        n = 0
        for row in reader:
            if row == target_row:
                data = row.split()[target_col]
                break
    
    print data
    

提交回复
热议问题