I have been trying to write a For loop to store all of the CSV files in a directory into one. The files in that directory were produced by another pandas program I wrote, and I have used "group.to_csv(f'data3/{station}.csv', index = False, encoding = "utf-8")" for them to make sure the encoding is utf-8.
The combining code I used is as follows:
import os import pandas as pd
master_df = pd.DataFrame() directory_path = '/pandas learning/data3'
for file in os.listdir (directory_path):
pd.read_csv(f'data3/{file}')
if file.endswith('.csv'):
master_df = master_df.append(pd.read_csv(f'data3/{file}'))
master_df.to_csv("final.csv" )
when I run the program, it gives me a UnicodeDecodeError, and since this code is for about 100 files I can't go and change the encoding of them 1 by 1.