Skip to content

DOC: elaborate on copies vs in place operations in comparison docs #38994

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 2 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/source/getting_started/comparison/comparison_with_sas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ see the :ref:`indexing documentation<indexing>` for much more on how to use an
``Index`` effectively.


Copies vs. in place operations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. include:: includes/copies.rst


Data input / output
-------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ particular row don't change.
See the :ref:`indexing documentation<indexing>` for much more on how to use an ``Index``
effectively.


Copies vs. in place operations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. include:: includes/copies.rst


Data input / output
-------------------

Expand Down
7 changes: 7 additions & 0 deletions doc/source/getting_started/comparison/comparison_with_sql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ structure.
tips = pd.read_csv(url)
tips


Copies vs. in place operations
------------------------------

.. include:: includes/copies.rst


SELECT
------
In SQL, selection is done using a comma-separated list of columns you'd like to select (or a ``*``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ see the :ref:`indexing documentation<indexing>` for much more on how to use an
``Index`` effectively.


Copies vs. in place operations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. include:: includes/copies.rst


Data input / output
-------------------

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

Keep certain columns
''''''''''''''''''''
Expand Down
23 changes: 23 additions & 0 deletions doc/source/getting_started/comparison/includes/copies.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Most pandas operations return copies of the ``Series``/``DataFrame``. To make the changes "stick",
you'll need to either assign to a new variable:

.. code-block:: python

sorted_df = df.sort_values("col1")


or overwrite the original one:

.. code-block:: python

df = df.sort_values("col1")

.. note::

You will see an ``inplace=True`` keyword argument available for some methods:

.. code-block:: python

df.sort_values("col1", inplace=True)

Its use is discouraged. :ref:`More information. <indexing.view_versus_copy>`