Skip to content
Justice Tech School

join and Index Alignment

join combines tables on their index. It is a shortcut for merge when the keys are the index labels.

Example
import pandas as pd
import numpy as np
a = pd.DataFrame({'x': [1, 2]}, index=['p', 'q'])
b = pd.DataFrame({'y': [3, 4]}, index=['q', 'r'])
print(a.join(b))
print(a.join(b, how='outer'))

Result

   x    y
p  1  NaN
q  2  3.0
     x    y
p  1.0  NaN
q  2.0  3.0
r  NaN  4.0

Exercise

Join by index.

a.(b)

Quiz Test

What does join match on?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.