Python Forum
pd.concat Problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: pd.concat Problem (/thread-27111.html)



pd.concat Problem - WiPi - May-26-2020

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.


RE: pd.concat Problem - WiPi - May-27-2020

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.