Python Forum
merge two csv files into output.csv using Subprocess
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
merge two csv files into output.csv using Subprocess
#4
Pandas can many times make stuff simpler.
import pandas as pd

df1 = pd.read_csv("1.csv")
df2 = pd.read_csv("2.csv")
df = pd.concat([df1, df2])
df.to_csv("output.csv", index=False)
Output:
Name,Age,Gender Jane Doe,32,Female John Smith,45,Male Kent smith,40,Male Tom Olsen,45,Male

Output:
1.csv Name,Age,Gender Jane Doe,32,Female John Smith,45,Male 2.csv Name,Age,Gender Kent smith,40,Male Tom Olsen,45,Male
Reply


Messages In This Thread
RE: merge two csv files into output.csv using Subprocess - by snippsat - Dec-08-2022, 01:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 3,624 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  I'm trying to merge 2 .csv files with no joy! Sick_Stigma 3 1,083 Aug-03-2024, 03:20 PM
Last Post: mariadsouza362
  Unexpected output when trying to attach files in a mail application PythonU2Novel 0 1,105 May-17-2024, 02:59 AM
Last Post: PythonU2Novel
  merge all xlsb files into csv mg24 0 873 Nov-13-2023, 08:25 AM
Last Post: mg24
  Merge all json files in folder after filtering deneme2 10 4,798 Sep-18-2022, 10:32 AM
Last Post: deneme2
  Increment text files output and limit contains Kaminsky 1 4,514 Jan-30-2021, 06:58 PM
Last Post: bowlofred
  How to merge all the files in a directory in to one file sutra 3 3,564 Dec-10-2020, 12:09 AM
Last Post: sutra
  opening files and output of parsing leodavinci1990 4 3,850 Oct-12-2020, 06:52 AM
Last Post: bowlofred
  Merge JSON Files Ugo 4 6,123 Aug-20-2020, 06:25 AM
Last Post: ndc85430
  How to get program output from subprocess.Popen? glestwid 1 3,234 Aug-19-2020, 05:44 AM
Last Post: buran

Forum Jump:

User Panel Messages

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