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
#6
You may also use Pandas and Numpy to deal with huge files; just an example here bellow

import pandas as pd
import numpy as np
import os

Path=str(os.getcwd())
CsvFile1='data1.csv' 
CsvFile2='data2.csv' 

# if you've a header (if not put it to False)
Header=True

# First csv file reading
File1=pd.read_csv(Path + '/' + CsvFile1, header=None, delimiter=';')
if Header : File1=File1.drop([0], axis=0)
Array1=File1.to_numpy(dtype=float)

# second csv file reading
File2=pd.read_csv(Path + '/' + CsvFile2, header=None, delimiter=';')
if Header : File2=File2.drop([0], axis=0)
Array2=File2.to_numpy(dtype=float)

# concatenation: you must have the same number of rows, but may have different number of columns
Concat=np.hstack((Array1, Array2))

# write a "like" csv file; remove fmt for the highest accuracy %.18e
# np.savetxt(Path + '/concat.csv', Concat, delimiter=';', fmt='%f')
np.savetxt(Path + '/concat.csv', Concat, delimiter=';')
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 paul18fr - Dec-14-2021, 07: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,221 Feb-21-2023, 04:21 AM
Last Post: Auz_Pete
  Sorting and Merging text-files [SOLVED] AlphaInc 10 4,975 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,808 Dec-09-2020, 05:14 PM
Last Post: sutra
  Merging Excel Files JezMim 1 1,925 Sep-06-2020, 08:56 PM
Last Post: bowlofred
  Merging CSV Files in Jupyter RJ117 0 4,788 Jan-07-2018, 06:24 AM
Last Post: RJ117
  merging two csv files jlcolam 3 11,449 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