Skip to content

Commit 6e271af

Browse files
committed
Added a description to the examples.
1 parent 7c28463 commit 6e271af

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

pandas/core/frame.py

+37-29
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,11 @@
138138
"""
139139

140140
_merge_doc = """
141-
Merge DataFrame or named Series objects by performing a database-style join
142-
operation by columns or indexes.
141+
Merge DataFrame or named Series objects with a database-style join.
143142
144-
If joining columns on columns, the DataFrame indexes *will be
145-
ignored*. Otherwise if joining indexes on indexes or indexes on a column or
146-
columns, the index will be passed on.
143+
The join is done on columns or indexes. If joining columns on
144+
columns, the DataFrame indexes *will be ignored*. Otherwise if joining indexes
145+
on indexes or indexes on a column or columns, the index will be passed on.
147146
148147
Parameters
149148
----------%s
@@ -153,13 +152,13 @@
153152
Type of merge to be performed.
154153
155154
* left: use only keys from left frame, similar to a SQL left outer join;
156-
preserve key order
155+
preserve key order.
157156
* right: use only keys from right frame, similar to a SQL right outer join;
158-
preserve key order
157+
preserve key order.
159158
* outer: use union of keys from both frames, similar to a SQL full outer
160-
join; sort keys lexicographically
159+
join; sort keys lexicographically.
161160
* inner: use intersection of keys from both frames, similar to a SQL inner
162-
join; preserve the order of the left keys
161+
join; preserve the order of the left keys.
163162
on : label or list
164163
Column or index level names to join on. These must be found in both
165164
DataFrames. If `on` is None and not merging on indexes then this defaults
@@ -172,23 +171,23 @@
172171
Column or index level names to join on in the right DataFrame. Can also
173172
be an array or list of arrays of the length of the right DataFrame.
174173
These arrays are treated as if they are columns.
175-
left_index : boolean, default False
174+
left_index : bool, default False
176175
Use the index from the left DataFrame as the join key(s). If it is a
177176
MultiIndex, the number of keys in the other DataFrame (either the index
178177
or a number of columns) must match the number of levels.
179-
right_index : boolean, default False
178+
right_index : bool, default False
180179
Use the index from the right DataFrame as the join key. Same caveats as
181180
left_index.
182-
sort : boolean, default False
181+
sort : bool, default False
183182
Sort the join keys lexicographically in the result DataFrame. If False,
184183
the order of the join keys depends on the join type (how keyword).
185-
suffixes : 2-length sequence (tuple, list, ...)
184+
suffixes : tuple of (str, str), default ('_x', '_y')
186185
Suffix to apply to overlapping column names in the left and right
187-
side, respectively. If (False, False), overlapping
188-
column names raise an error.
189-
copy : boolean, default True
186+
side, respectively. To raise an exception on overlapping columns use
187+
(False, False).
188+
copy : bool, default True
190189
If False, avoid copy if possible.
191-
indicator : boolean or string, default False
190+
indicator : bool or str, default False
192191
If True, adds a column to output DataFrame called "_merge" with
193192
information on the source of each row.
194193
If string, column with information on source of each row will be added to
@@ -198,7 +197,7 @@
198197
"right_only" for observations whose merge key only appears in 'right'
199198
DataFrame, and "both" if the observation's merge key is found in both.
200199
201-
validate : string, default None
200+
validate : str, default None
202201
If specified, checks if merge is of specified type.
203202
204203
* "one_to_one" or "1:1": check if merge keys are unique in both
@@ -213,7 +212,8 @@
213212
214213
Returns
215214
-------
216-
DataFrame
215+
df: DataFrame
216+
A DataFrame of the two merged objects.
217217
218218
Notes
219219
-----
@@ -230,24 +230,27 @@
230230
Examples
231231
--------
232232
233-
>>> A = pd.DataFrame({'lkey': ['foo', 'bar', 'baz', 'foo'],
233+
>>> df1 = pd.DataFrame({'lkey': ['foo', 'bar', 'baz', 'foo'],
234234
... 'value': [1, 2, 3, 5]})
235-
>>> B = pd.DataFrame({'rkey': ['foo', 'bar', 'baz', 'foo'],
235+
>>> df2 = pd.DataFrame({'rkey': ['foo', 'bar', 'baz', 'foo'],
236236
... 'value': [5, 6, 7, 8]})
237-
>>> A
237+
>>> df1
238238
lkey value
239239
0 foo 1
240240
1 bar 2
241241
2 baz 3
242242
3 foo 5
243-
>>> B
243+
>>> df2
244244
rkey value
245245
0 foo 5
246246
1 bar 6
247247
2 baz 7
248248
3 foo 8
249249
250-
>>> A.merge(B, left_on='lkey', right_on='rkey', how='outer')
250+
Merge df1 and df2 on the lkey and rkey columns. The value columns have
251+
the default suffixes, _x and _y, appended.
252+
253+
>>> df1.merge(df2, left_on='lkey', right_on='rkey')
251254
lkey value_x rkey value_y
252255
0 foo 1 foo 5
253256
1 foo 1 foo 8
@@ -256,8 +259,11 @@
256259
4 bar 2 bar 6
257260
5 baz 3 baz 7
258261
259-
>>> A.merge(B, left_on='lkey', right_on='rkey', how='outer',
260-
suffixes=('_left', '_right'))
262+
Merge DataFrames df1 and df2 with specified left and right suffixes
263+
appended to any overlapping columns.
264+
265+
>>> df1.merge(df2, left_on='lkey', right_on='rkey',
266+
... suffixes=('_left', '_right'))
261267
lkey value_left rkey value_right
262268
0 foo 1 foo 5
263269
1 foo 1 foo 8
@@ -266,10 +272,12 @@
266272
4 bar 2 bar 6
267273
5 baz 3 baz 7
268274
269-
>>> A.merge(B, left_on='lkey', right_on='rkey', how='outer',
270-
suffixes=(False, False))
275+
Merge DataFrames df1 and df2, but raise an exception if the DataFrames have
276+
any overlapping columns.
277+
278+
>>> df1.merge(df2, left_on='lkey', right_on='rkey', suffixes=(False, False))
271279
Traceback (most recent call last):
272-
...
280+
...
273281
ValueError: columns overlap but no suffix specified:
274282
Index(['value'], dtype='object')
275283
"""

0 commit comments

Comments
 (0)