I have CSVs in a folder, where I want to clean the headers (and only the headers) from special characters, then save the updated CSVs in a new folder.
The issue I'm having is that the special characters are removed from not only the headers, but also from the other rows below.
My code looks like this:
from pathlib import Path
import pandas as pd
import os
parent_dir = input("Enter CSV directory path:")
newdir = "Processed"
directory = os.path.join(parent_dir, newdir)
os.mkdir(directory)
csv_files = [f for f in Path(parent_dir).glob('*.csv')]
for csv in csv_files:
data = pd.read_csv(csv, encoding = 'ISO-8859-1', engine='python', delimiter = ',')
data.columns = data.columns.str.replace('[",@]','')
data.to_csv(parent_dir + "/Processed/" + csv.name, index=False)
Any suggestions on correcting this?