Python Forum
Help needed with merging two CSV files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help needed with merging two CSV files
#3
Well, csv is just text and the files are identical in format.

The only problem I see is if you have headers, then the headers will appear twice with the below, but that can be dealt with easily.

I have a lot of csv files I use as answer keys for OMR.

import glob

path2files = '/home/pedro/winter2021/OMR/20EAP/question_data_csv/'

files = glob.glob(path2files + '*.csv')

for file in files:
    print('The files are:', file)

file1 = input('Copy and paste 1 of the above files here ... ')
file2 = input('Copy and paste 1 of the above files here ... ')

with open(file1) as data1, open(file2) as data2:
    string1 = data1.read()
    string2 = data2.read()

amalgamate = string1 + string2
output = '/home/pedro/temp/output.csv'
with open(output, 'w') as o:
    o.write(amalgamate)

print('Only problem is the header row appears twice!')
eyadfr likes this post
Reply


Messages In This Thread
Help needed with merging two CSV files - by eyadfr - Dec-13-2021, 10:51 PM
RE: Help needed with merging two CSV files - by Pedroski55 - Dec-13-2021, 11:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Merging multiple csv files with same X,Y,Z in each Auz_Pete 3 1,220 Feb-21-2023, 04:21 AM
Last Post: Auz_Pete
  Sorting and Merging text-files [SOLVED] AlphaInc 10 4,969 Aug-20-2021, 05:42 PM
Last Post: snippsat
  Merging all file_name.log's files from directory to one and search “PerformanceINFO" sutra 0 1,807 Dec-09-2020, 05:14 PM
Last Post: sutra
  Merging Excel Files JezMim 1 1,922 Sep-06-2020, 08:56 PM
Last Post: bowlofred
  Merging CSV Files in Jupyter RJ117 0 4,787 Jan-07-2018, 06:24 AM
Last Post: RJ117
  merging two csv files jlcolam 3 11,441 Jul-13-2017, 06:59 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020