Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pd.concat Problem
#1
Hi guys,

I am struggling to get the pd.concat function to merge (or append) two csv files. Each file has 4 x columns with the same type of data. My code is:

import pandas as pd

a = pd.read_csv('test.csv')
b = pd.read_csv('test1.csv')
merged=pd.concat([a,b],axis = 0, ignore_index = True, sort='False')
merged.to_csv('merged_file.csv')
I've tried various versions of this as well as :

merged=a.append(b,sort=False)
The best I can get is for df 'b' to be put alongside 'a' and not at the end. Sometimes columns are also mixed up.

Any ideas please? I can send the test.csv files if needed.
Reply


Messages In This Thread
pd.concat Problem - by WiPi - May-26-2020, 01:34 PM
RE: pd.concat Problem - by WiPi - May-27-2020, 07:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  DataFRame.concat() nafshar 3 939 Jul-14-2023, 04:41 PM
Last Post: nafshar
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 6,520 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  Concat Strings paulo79 5 1,672 Apr-15-2022, 09:58 PM
Last Post: snippsat
  [SOLVED] Concat data from dictionary? Winfried 4 1,904 Mar-30-2022, 02:55 PM
Last Post: Winfried
  Sqlite CONCAT columns issac_n 4 5,368 Mar-22-2020, 09:31 AM
Last Post: buran
  Concat multiple Excel sheets with exclusion alessandrotk 1 2,951 Jan-10-2020, 04:43 AM
Last Post: sandeep_ganga

Forum Jump:

User Panel Messages

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