In [6]:
# 3.2 Combining Data Frames

In [2]:
# 3.2.1: Concatenation
import pandas as pd

In [5]:
# 3.2.1.1: Row concatenation (bottom-to-top)
x = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
y = pd.DataFrame({'a': [7, 8, 9], 'b': [10, 11, 12]})
df = pd.concat([x, y], axis=0)
# If axis is 0 (default), then glue on top of one another. Data frames should have the same columns. (similar to UNION in SQL or rbind in R)
# If axis is 1 (columns), then glue side-by-side.
print(df)
print(df.reset_index(drop=True))  # old indices are kept unless you reset index


   a   b
0  1   4
1  2   5
2  3   6
0  7  10
1  8  11
2  9  12
   a   b
0  1   4
1  2   5
2  3   6
3  7  10
4  8  11
5  9  12

In [ ]: