Skip to content

Commit 698a3d1

Browse files
committed
DOC: elaborate on copies vs in place operations in comparison docs
1 parent 68db2d2 commit 698a3d1

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed

doc/source/getting_started/comparison/comparison_with_sas.rst

Lines changed: 6 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ particular row don't change.
6262
See the :ref:`indexing documentation<indexing>` for much more on how to use an ``Index``
6363
effectively.
6464

65+
66+
Copies vs. in place operations
67+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68+
69+
.. include:: includes/copies.rst
70+
71+
6572
Commonly used spreadsheet functionalities
6673
-----------------------------------------
6774

doc/source/getting_started/comparison/comparison_with_sql.rst

Lines changed: 7 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 1 addition & 2 deletions
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
''''''''''''''''''''
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Most pandas operations return copies of the ``Series``/``DataFrame``. To make the changes "stick",
2+
you'll need to either:
3+
4+
* Assign back to the same variable
5+
6+
.. code-block:: python
7+
8+
df = df.sort_values("col1")
9+
10+
* Assign to a new variable
11+
12+
.. code-block:: python
13+
14+
sorted_df = df.sort_values("col1")
15+
16+
* Use the ``inplace=True`` keyword argument, where available
17+
18+
.. code-block:: python
19+
20+
df.sort_values("col1", inplace=True)

0 commit comments

Comments
 (0)