I use this to make a giant dataframe from many files in a directory:
path = r'C:\\Users\\me\\data\\'
all_files = glob.glob(os.path.join(path, "*"))
df_from_each_file = (pd.read_csv(f, sep='\t') for f in all_files)
concatdf = pd.concat(df_from_each_file, ignore_index=True)
The files in that path have names like
AAA.etc.etc.
AAA.etc.etc
BBB.etc.etc.
As I import each file, I want to add a column to the dataframe that has AAA or BBB next to all the rows imported from that file, like this:
col1 col2 col3
data1 data2 AAA
data3 data4 AAA
data1 data2 AAA
data3 data4 AAA
data1 data2 BBB
data3 data4 BBB
AAAorBBB?.read_csvfor each file, before concatenating, I want to add a column that has the partial filename.