python, pandas, csv import and more
Question: I have seen many questions in regards to importing multiple csv files into a
pandas dataframe. My question is how can you import multiple csv files but
ignore the last csv file in your directory? I have had a hard time finding the
answer to this.

Also, lets assume that the csv file names are all different which is why the
code file is "/*.csv"

any resource would also be greatly appreciated. Thank you!

    
    
    path =r'C:\DRO\DCL_rawdata_files' # use your path
    allFiles = glob.glob(path + "/*.csv")
    frame = pd.DataFrame()
    list_ = []
    for file_ in allFiles:
        df = pd.read_csv(file_,index_col=None, header=0)
        list_.append(df)
    frame = pd.concat(list_)
    


Answer: Try this:

    
    
    import os
    import glob
    import pandas as pd
    
    def get_merged_csv(flist, **kwargs):
        return pd.concat([pd.read_csv(f, **kwargs) for f in flist], ignore_index=True)
    
    path =r'C:\DRO\DCL_rawdata_files' # use your path
    fmask = os.path.join(path, '*.csv')
    allFiles = sorted(glob.glob(fmask), key=os.path.getmtime)
    
    frame = get_merged_csv(allFiles[:-1], index_col=None, header=0)
    

