Skip to content

Instantly share code, notes, and snippets.

@rathankalluri
Created July 26, 2018 12:50
Show Gist options
  • Save rathankalluri/14eafdad3714498e927f59eb07d32665 to your computer and use it in GitHub Desktop.
Save rathankalluri/14eafdad3714498e927f59eb07d32665 to your computer and use it in GitHub Desktop.
Remove row from CSV and store into New
import csv
import os
src = 'Users.csv'
dst = 'Users_new.csv'
with open(src, 'rb') as inp, open(dst, 'wb') as out:
writer = csv.writer(out)
reader = csv.reader(inp)
next(reader, None)
for row in reader:
if row[7] != 'DND': #Checking the value in the row
writer.writerow(row)
os.remove(src)
print "Original File Deleted"
os.rename(dst, src)
print ("File renamed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment