The join function

The DataFrame.join function is used to combine two DataFrames that have different columns with nothing in common. Essentially, this does a longitudinal join of two DataFrames. Here is an example:

df_1 = sales_data.iloc[0:5, 0:3]
df_2 = sales_data.iloc[3:8, 3:6]
df_1.join(df_2)

The following will be the output:

Default left join

join is almost identical to merge, the difference being that, while merge works for DataFrames that share identical keys, join combines DataFrames by the row-index. By default, the join function performs a left join. The other types of join can be specified through the how parameter:

df_1.join(df_2, how = "right")

The following will be the output:

Right join

The inner join can be performed as shown following:

df_1.join(df_2, how = "inner")

The following will be the output:

Inner join

The outer join can be performed as shown following:

df_1.join(df_2, how = "outer")

The following will be the output:

Outer join

If the two DataFrames being joined have a common column over which the join should be performed, the key or list of keys can be mentioned in the on parameter of the join function. This is just the same as a merge function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset