I'm currently trying to loop through all my csv files in a given folder (dest_dir), find a certain string in any file that may have it, and replace it with a different string. Whenever the code runs through, Nothing is being updated in any of the csv files. Why isnt this code reading the files and replacing the value with whats in the code?
import pandas as pd
import shutil
import os
import glob
import csv
src_dir = 'H:\\PCoE\\Users\\VanBecelaere_C\\Data Initiative Project\\Tables'
dest_dir = 'H:\\PCoE\\Users\\VanBecelaere_C\\Data Initiative Project\\Updated Tables'
files = os.listdir(src_dir)
shutil.copytree(src_dir, dest_dir)
print("Copy to new table complete")
for i in os.listdir(dest_dir):
files = os.path.join(dest_dir,i)
split= os.path.splitext(files)
if split[1]=='.FAC' or split[1]=='.RPT' or split[1]=='.FLX' or split[1]=='.fac':
os.rename(files,split[0]+'.csv')
print("Coverted to CSV")
csv_files = glob.glob(dest_dir + "/*.csv")
for file in csv_files:
df = pd.read_csv(file, encoding='UTF-8', sep='delimiter', header=1)
df.replace("NA_NRF", "FA_GUAR")
df.to_csv(file, index=False)