How to get every 3rd lines from a csv file using python?
import csv
with open ('data.csv','r') as infile:
contents = csv.reader(infile, delimiter =' ')
then???
The csv file looks like:
aaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbb
only recquired line
cccccccccccccccccccccccccc
ddddddddddddddddddddddddd
only recquired line
The result should look like:
only recquired line
only recquired line
To avoid loading the entire file into memory, you could use itertools.islice
from itertools import islice
with open ('data.csv','r') as infile:
x = islice(infile, 2, None, 3)
for line in x:
print line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With