-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpython_catalyst.py
More file actions
29 lines (22 loc) · 986 Bytes
/
Copy pathpython_catalyst.py
File metadata and controls
29 lines (22 loc) · 986 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
28
29
import csv
import os
folder = "/Users/JALAT/GIT/data-hub/app/assets/csv/catalyst"
for filename in os.listdir(folder):
if filename.endswith(".csv"):
filepath = os.path.join(folder, filename)
with open(filepath, "r", newline="", encoding="utf-8-sig") as f:
reader = csv.DictReader(f)
rows = list(reader)
fieldnames = reader.fieldnames
if "data_product_name" in fieldnames:
for row in rows:
value = row.get("data_product_name", "")
if value.endswith(" -catalyst"):
row["data_product_name"] = value.removesuffix(" -catalyst")
with open(filepath, "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(rows)
print(f"Updated {filename}")
else:
print(f"Skipped {filename} (column not found)")