I want to read only 1 column from file
and save it in the list column
. I have this code and I don't know how to optimize it. It takes lots of time because I need to call it a lot of times.
column = (sum(1 for line in open(file) if line.strip("\n")))*[0]
counter_row = 0
counter_column = 0
with open(file, 'r') as f:
for row in f:
row = row.strip("\n")
if row:
for el_column in row.split(","):
if counter_column==n_column:
column[counter_row]=el_column
counter_column = counter_column + 1
counter_row = counter_row + 1
counter_column = 0