Delete the first line of a CSV file

How to delete the first line of a CSV file in python, the first few lines of my CSV file:

Domain Name, ItemID, Auction Type, Time Left, Price, Bids, Domain Age, Traffic,ValuationPrice
TICKETFINE.COM,134774365,Bid,05/09/2014 08:00 AM (PDT),$100,0,0,0,$0
CREATINGMY.COM,134774390,Bid,05/09/2014 08:00 AM (PDT),$500,0,0,0,$0
WPTHEMEHELP.COM,134774444,Bid,05/09/2014 08:00 AM (PDT),$45,1,0,0,$0
APK-ZIPPY.COM,134774445,Bid,05/09/2014 08:00 AM (PDT),$10,0,0,0,$0
FAMILYBUZZMARKETING.COM,134689583,Bid,05/09/2014 08:00 AM (PDT),$90,0,0,0,$0
AMISRAGAS.COM,134689584,Bid,05/09/2014 08:00 AM (PDT),$35,0,0,0,$0
+4
source share
5 answers
with open("test.csv",'r') as f:
    with open("updated_test.csv",'w') as f1:
        next(f) # skip header line
        for line in f:
            f1.write(line)
+15
source

This is what I do when I want to skip reading the first line of the CSV.

All you have to do is call the function next()of the CSV object, in this case - read, and then the pointer to the reader will be on the next line.

import csv

try:
    read = csv.reader(f)
    read.next()     # Skip the first 'title' row.
    for r in read:
        # Do something
finally:
    # Close files and exit cleanly
    f.close()

Hope this is pretty simple for your purposes!

+1
source

- :

AttributeError: '_io.TextIOWrapper' object has no attribute 'next' python

Python3 next(). f.next().

f.readline(), .

next(f), @vrjr , .

+1

?

.

0
-1

Source: https://habr.com/ru/post/1540267/


All Articles