What's the fastest way to merge multiple csv files by column?

后端 未结 5 805
长情又很酷
长情又很酷 2021-02-09 04:08

I have about 50 CSV files with 60,000 rows in each, and a varying number of columns. I want to merge all the CSV files by column. I\'ve tried doing this in MATLAB by transposing

5条回答
  •  死守一世寂寞
    2021-02-09 04:57

    The Python csv module can be set up so that each record is a dictionary with the column names as keys. You should that way be able to read in all the files as dictionaries, and write them to an out-file that has all columns.

    Python is easy to use, so this should be fairly trivial for a programmer of any language.

    If your csv-files doesn't have column headings, this will be quite a lot of manual work, though, so then it's perhaps not the best solution.

    Since these files are fairly big, it's best not to read all of them into memory once. I'd recommend that you first open them only to collect all column names into a list, and use that list to create the output file. Then you can concatenate each input file to the output file without having to have all of the files in memory.

提交回复
热议问题