MCPcopy
hub / github.com/pandas-dev/pandas / merge

Function merge

pandas/core/reshape/merge.py:146–399  ·  view source on GitHub ↗

Merge DataFrame or named Series objects with a database-style join. A named Series object is treated as a DataFrame with a single named column. The join is done on columns or indexes. If joining columns on columns, the DataFrame indexes *will be ignored*. Otherwise if joining inde

(
    left: DataFrame | Series,
    right: DataFrame | Series,
    how: MergeHow = "inner",
    on: IndexLabel | AnyArrayLike | None = None,
    left_on: IndexLabel | AnyArrayLike | None = None,
    right_on: IndexLabel | AnyArrayLike | None = None,
    left_index: bool = False,
    right_index: bool = False,
    sort: bool = False,
    suffixes: Suffixes = ("_x", "_y"),
    copy: bool | lib.NoDefault = lib.no_default,
    indicator: str | bool = False,
    validate: str | None = None,
)

Source from the content-addressed store, hash-verified

144
145@set_module("pandas")
146def merge(
147 left: DataFrame | Series,
148 right: DataFrame | Series,
149 how: MergeHow = "inner",
150 on: IndexLabel | AnyArrayLike | None = None,
151 left_on: IndexLabel | AnyArrayLike | None = None,
152 right_on: IndexLabel | AnyArrayLike | None = None,
153 left_index: bool = False,
154 right_index: bool = False,
155 sort: bool = False,
156 suffixes: Suffixes = ("_x", "_y"),
157 copy: bool | lib.NoDefault = lib.no_default,
158 indicator: str | bool = False,
159 validate: str | None = None,
160) -> DataFrame:
161 """
162 Merge DataFrame or named Series objects with a database-style join.
163
164 A named Series object is treated as a DataFrame with a single named column.
165
166 The join is done on columns or indexes. If joining columns on
167 columns, the DataFrame indexes *will be ignored*. Otherwise if joining indexes
168 on indexes or indexes on a column or columns, the index will be passed on.
169 When performing a cross merge, no column specifications to merge on are
170 allowed.
171
172 .. warning::
173
174 If both key columns contain rows where the key is a null value, those
175 rows will be matched against each other. This is different from usual SQL
176 join behaviour and can lead to unexpected results.
177
178 Parameters
179 ----------
180 left : DataFrame or named Series
181 First pandas object to merge.
182 right : DataFrame or named Series
183 Second pandas object to merge.
184 how : {'left', 'right', 'outer', 'inner', 'cross', 'left_anti', 'right_anti},
185 default 'inner'
186 Type of merge to be performed.
187
188 * left: use only keys from left frame, similar to a SQL left outer join;
189 preserve key order.
190 * right: use only keys from right frame, similar to a SQL right outer join;
191 preserve key order.
192 * outer: use union of keys from both frames, similar to a SQL full outer
193 join; sort keys lexicographically.
194 * inner: use intersection of keys from both frames, similar to a SQL inner
195 join; preserve the order of the left keys.
196 * cross: creates the cartesian product from both frames, preserves the order
197 of the left keys.
198 * left_anti: use only keys from left frame that are not in right frame, similar
199 to SQL left anti join; preserve key order.
200 * right_anti: use only keys from right frame that are not in left frame, similar
201 to SQL right anti join; preserve key order.
202 on : Hashable or a sequence of the previous
203 Column or index level names to join on. These must be found in both

Callers 15

time_merge_2intkeyMethod · 0.90
time_mergeMethod · 0.90
time_i8mergeMethod · 0.90
time_unique_mergeMethod · 0.90
time_mergeMethod · 0.90
time_merge_objectMethod · 0.90
time_merge_catMethod · 0.90

Calls 5

_validate_operandFunction · 0.85
_cross_mergeFunction · 0.85
_MergeOperationClass · 0.85
get_resultMethod · 0.45