Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

join three pandas data frames into one?

Tags:

python

pandas

Here is my pandas Data Frames:

pandas1 = pandas.DataFrame([1,2,3,4,5,6,7,8,9])
pandas2 = pandas.DataFrame([10,20,30,40,50,60,70,80,90])
pandas3 = pandas.DataFrame([100,200,300,400,500,600,700,800,900])

How can I meld this there Data Frames into one,like so:

1,10,100
2,20,200
3,30,300
4,40,400
5,50,500
6,60,600
7,70,700
8,80,800
9,90,900
like image 929
Michael Avatar asked Jul 27 '26 02:07

Michael


1 Answers

You can use this:

pandas1.join(pandas2, lsuffix ="2").join(pandas3, lsuffix="3")

the lsuffix is only required because all of your columns have the same default name of (0)

This code is actually joining the dataframes on their indexes. See http://pandas.pydata.org/pandas-docs/dev/merging.html#database-style-dataframe-joining-merging

EDIT:

If you are trying to join Series objects rather than Dataframes, then you want

pandas.concat([pandas1, pandas2, pandas3], axis=1) 
like image 120
RobinL Avatar answered Jul 29 '26 16:07

RobinL