python add new column to dataframe with same or different length with pandas

description: add new column to a dataframe

initial data

1
2
3
4
5
6
a = pandas.DataFrame({'a':[1,2,3]})
# a
# a
# 0 1
# 1 2
# 2 3
1
2
3
4
5
6
b = pandas.DataFrame({'b':[2,4,6]})
# b
# b
# 0 2
# 1 4
# 2 6
1
2
3
4
5
6
7
8
c = pandas.DataFrame({'c':[1,2,3,4,5]})
# c
# c
# 0 1
# 1 2
# 2 3
# 3 4
# 4 5

concat the same length

1
2
3
4
5
pandas.concat([a,b], axis=1)
# a b
# 0 1 2
# 1 2 4
# 2 3 6

concat different length

1
2
3
4
5
6
7
pandas.concat([a,c], axis=1)
# a c
# 0 1.0 1
# 1 2.0 2
# 2 3.0 3
# 3 NaN 4
# 4 NaN 5