pandas equivalent of R's cbind (concatenate/stack vectors vertically)

uday picture uday · Feb 19, 2015 · Viewed 55.6k times · Source

suppose I have two dataframes:

import pandas
....
....
test1 = pandas.DataFrame([1,2,3,4,5])
....
....
test2 = pandas.DataFrame([4,2,1,3,7])
....

I tried test1.append(test2) but it is the equivalent of R's rbind.

How can I combine the two as two columns of a dataframe similar to the cbind function in R?

Answer

cphlewis picture cphlewis · Feb 19, 2015
test3 = pd.concat([test1, test2], axis=1)
test3.columns = ['a','b']