Skip to content

Commit 510bc20

Browse files
authored
DOC: elaborate on copies vs in place operations in comparison docs (#38994)
1 parent 588b634 commit 510bc20

File tree

6 files changed

+50
-2
lines changed

6 files changed

+50
-2
lines changed

doc/source/getting_started/comparison/comparison_with_sas.rst

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ see the :ref:`indexing documentation<indexing>` for much more on how to use an
6262
``Index`` effectively.
6363

6464

65+
Copies vs. in place operations
66+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67+
68+
.. include:: includes/copies.rst
69+
70+
6571
Data input / output
6672
-------------------
6773

doc/source/getting_started/comparison/comparison_with_spreadsheets.rst

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ particular row don't change.
6565
See the :ref:`indexing documentation<indexing>` for much more on how to use an ``Index``
6666
effectively.
6767

68+
69+
Copies vs. in place operations
70+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71+
72+
.. include:: includes/copies.rst
73+
74+
6875
Data input / output
6976
-------------------
7077

doc/source/getting_started/comparison/comparison_with_sql.rst

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ structure.
2323
tips = pd.read_csv(url)
2424
tips
2525
26+
27+
Copies vs. in place operations
28+
------------------------------
29+
30+
.. include:: includes/copies.rst
31+
32+
2633
SELECT
2734
------
2835
In SQL, selection is done using a comma-separated list of columns you'd like to select (or a ``*``

doc/source/getting_started/comparison/comparison_with_stata.rst

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ see the :ref:`indexing documentation<indexing>` for much more on how to use an
6161
``Index`` effectively.
6262

6363

64+
Copies vs. in place operations
65+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66+
67+
.. include:: includes/copies.rst
68+
69+
6470
Data input / output
6571
-------------------
6672

doc/source/getting_started/comparison/includes/column_selection.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
The same operations are expressed in pandas below. Note that these operations do not happen in
2-
place. To make these changes persist, assign the operation back to a variable.
1+
The same operations are expressed in pandas below.
32

43
Keep certain columns
54
''''''''''''''''''''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Most pandas operations return copies of the ``Series``/``DataFrame``. To make the changes "stick",
2+
you'll need to either assign to a new variable:
3+
4+
.. code-block:: python
5+
6+
sorted_df = df.sort_values("col1")
7+
8+
9+
or overwrite the original one:
10+
11+
.. code-block:: python
12+
13+
df = df.sort_values("col1")
14+
15+
.. note::
16+
17+
You will see an ``inplace=True`` keyword argument available for some methods:
18+
19+
.. code-block:: python
20+
21+
df.sort_values("col1", inplace=True)
22+
23+
Its use is discouraged. :ref:`More information. <indexing.view_versus_copy>`

0 commit comments

Comments
 (0)