-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCSVEdit.py
More file actions
21 lines (18 loc) · 800 Bytes
/
CSVEdit.py
File metadata and controls
21 lines (18 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import csv
import os
from tkinter.filedialog import askopenfilename
## Modify this line to change logic of fields to keep
keepers = ("StartTime-LocalYYYYMMDD_HHMMSS", "EndTime-LocalYYYYMMDD_HHMMSS", "-Value", ".Latitude", ".Longitude", ".Accuracy")
fileName, fileExtension = os.path.splitext(askopenfilename(filetypes=[("Sapelli CSV", "*.csv")]))
oldFile = fileName + fileExtension
newFile = fileName + '_new' + fileExtension
fieldsToKeep = []
with open(oldFile) as infile, open(newFile, "w", newline="") as outfile:
r = csv.DictReader(infile)
for fieldName in r.fieldnames:
if fieldName.endswith(keepers):
fieldsToKeep.append(fieldName)
w = csv.DictWriter(outfile, fieldsToKeep, extrasaction="ignore")
w.writeheader()
for row in r:
w.writerow(row)