Skip to content

DOC: Improve examples of df.append to better show the ignore_index param #41444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 17, 2021
17 changes: 9 additions & 8 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8793,6 +8793,7 @@ def append(
Returns
-------
DataFrame
A new DataFrame consisting of the rows of caller and the rows of `other`.

See Also
--------
Expand All @@ -8811,18 +8812,18 @@ def append(

Examples
--------
>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'), index=['x', 'y'])
>>> df
A B
0 1 2
1 3 4
>>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
x 1 2
y 3 4
>>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'), index=['x', 'y'])
>>> df.append(df2)
A B
0 1 2
1 3 4
0 5 6
1 7 8
x 1 2
y 3 4
x 5 6
y 7 8

With `ignore_index` set to True:

Expand Down