Skip to content

Commit c697ca6

Browse files
Triple0WillAyd
authored andcommitted
DOC: Improve the docstring of pandas.DataFrame.append() (pandas-dev#20267)
1 parent 3391c22 commit c697ca6

File tree

1 file changed

+50
-39
lines changed

1 file changed

+50
-39
lines changed

pandas/core/frame.py

+50-39
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@
145145
146146
Parameters
147147
----------%s
148-
right : DataFrame
148+
right : DataFrame, Series or dict
149+
Object to merge with.
149150
how : {'left', 'right', 'outer', 'inner'}, default 'inner'
151+
Type of merge to be performed.
152+
150153
* left: use only keys from left frame, similar to a SQL left outer join;
151154
preserve key order
152155
* right: use only keys from right frame, similar to a SQL right outer join;
@@ -170,18 +173,18 @@
170173
left_index : boolean, default False
171174
Use the index from the left DataFrame as the join key(s). If it is a
172175
MultiIndex, the number of keys in the other DataFrame (either the index
173-
or a number of columns) must match the number of levels
176+
or a number of columns) must match the number of levels.
174177
right_index : boolean, default False
175178
Use the index from the right DataFrame as the join key. Same caveats as
176-
left_index
179+
left_index.
177180
sort : boolean, default False
178181
Sort the join keys lexicographically in the result DataFrame. If False,
179-
the order of the join keys depends on the join type (how keyword)
182+
the order of the join keys depends on the join type (how keyword).
180183
suffixes : 2-length sequence (tuple, list, ...)
181184
Suffix to apply to overlapping column names in the left and right
182-
side, respectively
185+
side, respectively.
183186
copy : boolean, default True
184-
If False, do not copy data unnecessarily
187+
If False, avoid copy if possible.
185188
indicator : boolean or string, default False
186189
If True, adds a column to output DataFrame called "_merge" with
187190
information on the source of each row.
@@ -205,41 +208,49 @@
205208
206209
.. versionadded:: 0.21.0
207210
211+
Returns
212+
-------
213+
DataFrame
214+
208215
Notes
209216
-----
210217
Support for specifying index levels as the `on`, `left_on`, and
211218
`right_on` parameters was added in version 0.23.0
212219
220+
See Also
221+
--------
222+
merge_ordered : merge with optional filling/interpolation.
223+
merge_asof : merge on nearest keys.
224+
DataFrame.join : similar method using indices.
225+
213226
Examples
214227
--------
215228
216-
>>> A >>> B
217-
lkey value rkey value
218-
0 foo 1 0 foo 5
219-
1 bar 2 1 bar 6
220-
2 baz 3 2 qux 7
221-
3 foo 4 3 bar 8
229+
>>> A = pd.DataFrame({'lkey': ['foo', 'bar', 'baz', 'foo'],
230+
... 'value': [1, 2, 3, 5]})
231+
>>> B = pd.DataFrame({'rkey': ['foo', 'bar', 'baz', 'foo'],
232+
... 'value': [5, 6, 7, 8]})
233+
>>> A
234+
lkey value
235+
0 foo 1
236+
1 bar 2
237+
2 baz 3
238+
3 foo 5
239+
>>> B
240+
rkey value
241+
0 foo 5
242+
1 bar 6
243+
2 baz 7
244+
3 foo 8
222245
223246
>>> A.merge(B, left_on='lkey', right_on='rkey', how='outer')
224-
lkey value_x rkey value_y
225-
0 foo 1 foo 5
226-
1 foo 4 foo 5
227-
2 bar 2 bar 6
228-
3 bar 2 bar 8
229-
4 baz 3 NaN NaN
230-
5 NaN NaN qux 7
231-
232-
Returns
233-
-------
234-
merged : DataFrame
235-
The output type will the be same as 'left', if it is a subclass
236-
of DataFrame.
237-
238-
See also
239-
--------
240-
merge_ordered
241-
merge_asof
242-
DataFrame.join
247+
lkey value_x rkey value_y
248+
0 foo 1 foo 5
249+
1 foo 1 foo 8
250+
2 foo 5 foo 5
251+
3 foo 5 foo 8
252+
4 bar 2 bar 6
253+
5 baz 3 baz 7
243254
"""
244255

245256
# -----------------------------------------------------------------------
@@ -3244,14 +3255,15 @@ def insert(self, loc, column, value, allow_duplicates=False):
32443255

32453256
def assign(self, **kwargs):
32463257
r"""
3247-
Assign new columns to a DataFrame, returning a new object
3248-
(a copy) with the new columns added to the original ones.
3258+
Assign new columns to a DataFrame.
3259+
3260+
Returns a new object with all original columns in addition to new ones.
32493261
Existing columns that are re-assigned will be overwritten.
32503262
32513263
Parameters
32523264
----------
32533265
kwargs : keyword, value pairs
3254-
keywords are the column names. If the values are
3266+
The column names are keywords. If the values are
32553267
callable, they are computed on the DataFrame and
32563268
assigned to the new columns. The callable must not
32573269
change input DataFrame (though pandas doesn't check it).
@@ -3276,7 +3288,7 @@ def assign(self, **kwargs):
32763288
32773289
.. versionchanged :: 0.23.0
32783290
3279-
Keyword argument order is maintained for Python 3.6 and later.
3291+
Keyword argument order is maintained for Python 3.6 and later.
32803292
32813293
Examples
32823294
--------
@@ -6250,8 +6262,9 @@ def infer(x):
62506262
def append(self, other, ignore_index=False,
62516263
verify_integrity=False, sort=None):
62526264
"""
6253-
Append rows of `other` to the end of this frame, returning a new
6254-
object. Columns not in this frame are added as new columns.
6265+
Append rows of `other` to the end of caller, returning a new object.
6266+
6267+
Columns in `other` that are not in the caller are added as new columns.
62556268
62566269
Parameters
62576270
----------
@@ -6341,7 +6354,6 @@ def append(self, other, ignore_index=False,
63416354
2 2
63426355
3 3
63436356
4 4
6344-
63456357
"""
63466358
if isinstance(other, (Series, dict)):
63476359
if isinstance(other, dict):
@@ -6611,7 +6623,6 @@ def round(self, decimals=0, *args, **kwargs):
66116623
--------
66126624
numpy.around
66136625
Series.round
6614-
66156626
"""
66166627
from pandas.core.reshape.concat import concat
66176628

0 commit comments

Comments
 (0)