I have around 500 datasets in a folder that I wish to concatenate. They all have the same column names: 'Year', 'ZIP Code, 'Var1', 'Var2', 'Var3'.
I used the following code to loop through the files in the folder:
directory = '/MyDirectory'
os.chdir(directory)
files = os.listdir()
for f in files:
if f.endswith('.csv'):
combined_dataset = pd.concat([pd.read_csv(f)])
When I output the dataset, only the dataset for the year 2019 and zip code 000001 appears. I printed the whole list of files and the datasets I'm seeking to concatenate are all there. Any insight into why this might be the case? Thanks!