0

I have a program which should merge multiple csv files

def merge( csv_output_path):
    os.chdir("output/filtered")

    all_filenames = "output/filtered/filtered.csv"
    extension = "csv"
    all_filenames = [i for i in glob.glob( 'output/filtered/filtered.csv')]

    #combine all files in the list
    all_filenames = [i for i in glob.glob('*.{}'.format(extension))]

    #combine all files in the list
    combined_csv = pd.concat(map([pd.read_csv(file) for file in all_filenames ]), axis=1, join='outer').sort_index()
    #export to csv
    combined_csv.to_csv( "MergedFiles.csv", index=False, encoding='utf-8-sig')

The code above does not join all these files by column. How can I join all these files that have only one column in common timestamps.

fileA.csv

enter image description here

fileB.csv

enter image description here

martineau
  • 119,623
  • 25
  • 170
  • 301
  • Does this answer your question? [Pandas Merging 101](https://stackoverflow.com/questions/53645882/pandas-merging-101) – It_is_Chris Jan 24 '22 at 20:30
  • I've tried using the pd.merege method but i think because I have a lot of files it takes a lot longer to merge two files at once – user17572005 Jan 24 '22 at 20:45
  • 1
    By the way, all_filenames is being defined three times, and the value is discarded without any effect the first two times (removing the first two lines with all_filenames would have no effect on your function). – Jakob Schödl Jan 24 '22 at 20:46

0 Answers0