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: I want to append one of them to the end of the other - NOT side by side i.e not creating 8 columns.
|