-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredactCSV.py
More file actions
27 lines (24 loc) · 838 Bytes
/
Copy pathredactCSV.py
File metadata and controls
27 lines (24 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import csv
import os
import string
import random
filestoremove = []
for filename in os.listdir():
if ".csv" in filename and "redacted" not in filename:
print("\n" + filename )
filestoremove.append(filename)
for FILE in filestoremove:
csvfile = open(FILE, "r")
csvReader = csv.reader(csvfile, delimiter=',')
finishList = []
finishList.append(next(csvReader))
for row in csvReader:
for count,cell in enumerate(row):
new_string = cell.translate(str.maketrans('', '', string.punctuation))
if new_string.isdigit():
row[count] = random.randint(0,1000)
finishList.append(row)
csvfile.close()
csvfile = open("redacted_{}".format(FILE), "w")
csvWriter = csv.writer(csvfile, delimiter = ",")
csvWriter.writerows(finishList)