try: df = pd.read_csv(file_path) # Read CSV into DataFrame print("Delimiter is already ','.") except: df = pd.read_csv(file_path,delimiter=';') # Read CSV into DataFrame print("Converting delimiter...") df.to_csv(file_path, sep=',', index=False) # Write DataFrame with ',' delimiter print("File converted and overwritten.")
Folder containing CSV files
folder_path = r'./data'
Iterate over each file in the folder
for filename in os.listdir(folder_path): if filename.endswith('.csv'): # Check if file is CSV file_path = os.path.join(folder_path, filename) process_csv(file_path) # Process the CSV file