Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find specific row in Python CSV module

Tags:

python

csv

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 I get specifically the third row?

like image 262
Sam Avatar asked Aug 30 '25 17:08

Sam


1 Answers

You could convert the csv reader object into a list of lists... The rows are stored in a list, which contains lists of the columns.

So:

csvr = csv.reader(file)
csvr = list(csvr)
csvr[2]     # The 3rd row
csvr[2][3]  # The 4th column on the 3rd row.
csvr[-4][-3]# The 3rd column from the right on the 4th row from the end
like image 61
MrAlexBailey Avatar answered Sep 02 '25 07:09

MrAlexBailey