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
#2
sorry I maybe should have put more explanation content so the 2 files have data exactly like this:

Output:
2020.05.15 15:00 EURJPY Sell 0.14 115.548 2020.05.15 16:00 EURJPY Sell 0.22 115.772 2020.05.18 16:00 EURJPY Sell 0.34 116.45 2020.05.18 21:00 EURJPY Sell 0.53 117.184 2020.05.19 14:00 EURJPY Sell 0.8 118.039 2020.05.22 16:00 USDCAD Buy 0.15 1.40362 2020.05.22 20:00 USDCAD Buy 0.23 1.40155 2020.05.25 10:00 EURUSD Sell 0.15 1.08785 2020.05.25 11:00 USDCHF Buy 0.15 0.97336 2020.05.25 12:00 EURUSD Sell 0.23 1.08885 2020.05.25 12:00 USDCHF Buy 0.23 0.97253 2020.05.25 20:00 USDCAD Buy 0.15 1.39864
I want to append one of them to the end of the other - NOT side by side i.e not creating 8 columns.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  DataFRame.concat() nafshar 3 772 Jul-14-2023, 04:41 PM
Last Post: nafshar
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,586 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  Concat Strings paulo79 5 1,440 Apr-15-2022, 09:58 PM
Last Post: snippsat
  [SOLVED] Concat data from dictionary? Winfried 4 1,717 Mar-30-2022, 02:55 PM
Last Post: Winfried
  Sqlite CONCAT columns issac_n 4 5,071 Mar-22-2020, 09:31 AM
Last Post: buran
  Concat multiple Excel sheets with exclusion alessandrotk 1 2,839 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