Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is the process for reading a csv file and extracting the second element in each row:

  1. Import the csv module:
import csv
  1. Open the csv file using the csv.reader function:
with open('filename.csv') as csvfile:
    reader = csv.reader(csvfile)
  1. Use a loop to iterate over each row in the csv file:
for row in reader:
  1. Extract the second element in each row using indexing (remember that indexing starts at 0):
second_element = row[1]
  1. Use the second element as needed:
print(second_element)