I want to know whether it is possible to read the .csv file with specific row, after reading the row. I want to delete that specific row and update the .csv file with next row gets ascended. Assuming the .csv file has headers. If it is possible than how?
Ex. below is my sample.csv
Time A B
12:25 5.6 4.5
12:30 1.2 -3.4
12:35 4.7 -4.0
Below is the code I have tried:
import csv
with open('sample.csv', 'rb') as inp, open('sample.csv', "a") as out:
writer = csv.writer(out)
for row in csv.reader(inp):
writer.writerow(row)
But it gets, appended at the end of file. I have also tried to write it on the temporary file for intermediate stage. But, it still not serve my purpose cause I have to work on the same file. Here is the output sample.csv, which I want after one iteration of read:
Time A B
12:30 1.2 -3.4
12:35 4.7 -4.0
python. I have gone through [basic links] (stackoverflow.com/questions/16020858/…). Implement that code could not serve my purpose.shutilcode.