Search code examples
pythonpandasdataframeseries

Add two columns one below other in pandas


I have a big DataFrame and I`m trying to transform 2 columns(Series) into 1.

Example:

print(df['col1'])
0 1
1 2
2 3
print(df['col2'])
0 7
1 8
2 9

Output:

print(df['singleCol'])
0 1
1 2
2 3
3 7
4 8
5 9

Is this possible using Pandas?


Solution

  • series1 = pd.Series(df['col1'])
    series2 = pd.Series(df['col2'])
    df = pd.concat([series1, series2], axis = 0)