🎗 Join function in pandas 🎗
🎗 The join() function is used to join columns of another DataFrame.
🎗 Join columns with other DataFrame either on index or on a key column. Efficiently join multiple DataFrame objects by index at once by passing a list.
Syntax:
DataFrame.join(self, other, on=None, how='left', lsuffix='', rsuffix='', sort=False)
Parameters:
🎗 other
🎗 on
🎗 how
🎗 lsuffix
🎗 rsuffix
🎗 sort
☝🏻other
→ Index should be similar to one of the columns in this one.
→ If a Series is passed, its name attribute must be set, and that will be used as the column name in the resulting joined DataFrame.
Type/Default Value
DataFrame, Series, or list of DataFrame
🤞🏻On
→ Column or index level name(s) in the caller to join on the index in other, otherwise joins index-on-index.
→ If multiple values given, the other DataFrame must have a MultiIndex.
→ Can pass an array as the join key if it is not already contained in the calling DataFrame. Like an Excel VLOOKUP operation.
Type/Default Value
str, list of str, or array-like
👌🏻how
→ How to handle the operation of the two objects.
- left: use calling frame’s index (or column if on is specified)
- right: use other’s index.
- outer: form union of calling frame’s index (or column if on is specified) with other’s index, and sort it. lexicographically.
- inner: form intersection of calling frame’s index (or column if on is specified) with other’s index, preserving the order of the calling’s one.
Type/Default Value
{‘left’, ‘right’, ‘outer’, ‘inner’}
Default Value: ‘left’
🖖🏻lsuffix
→ Suffix to use from right frame’s overlapping columns.
Type/Default Value
str
Default Value: ”
🖐🏻rsuffix
→ Suffix to use from right frame’s overlapping columns.
Type/Default Value
str
Default Value: ‘’
✊🏻sort
→ Order result DataFrame lexicographically by the join key. If False, the order of the join key depends on the join type (how keyword)
Type/Default Value
bool
Default Value: False
Returns: DataFrame
A dataframe containing columns from both the caller and other.
Example🎗
Thanks All 🤍!
Have a great day💌.
See you in next blog🎈.