I have some code that looks like this:
import pandas as pd
import glob
root_directory = r"\\some\shared\directory"
all_files = glob.glob(f'{root_directory}\CPE_*.csv')
li = []
for filename in all_files:
frame = pd.read_csv(filename, index_col=None, header=0, encoding='latin1')
li.append(frame)
df = pd.concat(li, axis=0, ignore_index=True)
This code allows me to concatenate the data and create a master csv file, but I want to add a new column to each dataframe as I loop through them. The file names look something like this: CPE_02082020.csv , CPE_02092020 , etc. So the date is in the file name itself with the format of mmddyyyy. How do I add a date column to each file as I loop through and concatenate them?