We want to delete the first 34 rows of our csv file, as it is useless text headers, which is to no use. We are trying to do so by running the following lines of code in Python 3:
with open("test.csv",'r') as f, open("temp.csv",'w') as f1:
next(f) # skip header line
for line in f:
f1.write(line)
Above should only 'delete' first line, but we imagine we could make a for loop with range(0, 35) around next(f). Although that doesn't seem like the "pythonical" way of solving this.
Our data is in test.csv, and we have an empty csv file called temp.csv. The code described above is supposed to skip first line of test.csv, and then copy the rest into temp.csv.
Unfortunately we receive this error:
Traceback (most recent call last):
File "delete.py", line 2, in <module>
next(f) # skip header line
File "/usr/lib/python3.6/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf8 in position 2625: invalid start byte
Why does this occur? And what is the pythonical way of deleting the first 34 rows in a csv file?