diff --git a/doc/source/getting_started/comparison/includes/copies.rst b/doc/source/getting_started/comparison/includes/copies.rst index 08ccd47624932..e55d085faecb3 100644 --- a/doc/source/getting_started/comparison/includes/copies.rst +++ b/doc/source/getting_started/comparison/includes/copies.rst @@ -11,13 +11,3 @@ 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. ` diff --git a/doc/source/user_guide/advanced.rst b/doc/source/user_guide/advanced.rst index b8df21ab5a5b4..6c2972c77ede2 100644 --- a/doc/source/user_guide/advanced.rst +++ b/doc/source/user_guide/advanced.rst @@ -609,7 +609,7 @@ are named. .. ipython:: python - s.index.set_names(["L1", "L2"], inplace=True) + s.index = s.index.set_names(["L1", "L2"]) s.sort_index(level="L1") s.sort_index(level="L2") diff --git a/doc/source/user_guide/basics.rst b/doc/source/user_guide/basics.rst index f30c66d75b525..bdd216b750efa 100644 --- a/doc/source/user_guide/basics.rst +++ b/doc/source/user_guide/basics.rst @@ -1479,11 +1479,6 @@ you specify a single ``mapper`` and the ``axis`` to apply that mapping to. df.rename({"one": "foo", "two": "bar"}, axis="columns") df.rename({"a": "apple", "b": "banana", "d": "durian"}, axis="index") - -The :meth:`~DataFrame.rename` method also provides an ``inplace`` named -parameter that is by default ``False`` and copies the underlying data. Pass -``inplace=True`` to rename the data in place. - Finally, :meth:`~Series.rename` also accepts a scalar or list-like for altering the ``Series.name`` attribute. diff --git a/doc/source/user_guide/categorical.rst b/doc/source/user_guide/categorical.rst index f3d68f4c471c1..e031a1443bc6f 100644 --- a/doc/source/user_guide/categorical.rst +++ b/doc/source/user_guide/categorical.rst @@ -437,9 +437,9 @@ meaning and certain operations are possible. If the categorical is unordered, `` .. ipython:: python s = pd.Series(pd.Categorical(["a", "b", "c", "a"], ordered=False)) - s.sort_values(inplace=True) + s = s.sort_values() s = pd.Series(["a", "b", "c", "a"]).astype(CategoricalDtype(ordered=True)) - s.sort_values(inplace=True) + s = s.sort_values() s s.min(), s.max() @@ -459,7 +459,7 @@ This is even true for strings and numeric data: s = pd.Series([1, 2, 3, 1], dtype="category") s = s.cat.set_categories([2, 3, 1], ordered=True) s - s.sort_values(inplace=True) + s = s.sort_values() s s.min(), s.max() @@ -477,7 +477,7 @@ necessarily make the sort order the same as the categories order. s = pd.Series([1, 2, 3, 1], dtype="category") s = s.cat.reorder_categories([2, 3, 1], ordered=True) s - s.sort_values(inplace=True) + s = s.sort_values() s s.min(), s.max() diff --git a/doc/source/user_guide/enhancingperf.rst b/doc/source/user_guide/enhancingperf.rst index 9375bb066781b..0909d5cd91355 100644 --- a/doc/source/user_guide/enhancingperf.rst +++ b/doc/source/user_guide/enhancingperf.rst @@ -647,24 +647,21 @@ This allows for *formulaic evaluation*. The assignment target can be a new column name or an existing column name, and it must be a valid Python identifier. -The ``inplace`` keyword determines whether this assignment will performed -on the original :class:`DataFrame` or return a copy with the new column. - .. ipython:: python df = pd.DataFrame(dict(a=range(5), b=range(5, 10))) - df.eval("c = a + b", inplace=True) - df.eval("d = a + b + c", inplace=True) - df.eval("a = 1", inplace=True) + df = df.eval("c = a + b") + df = df.eval("d = a + b + c") + df = df.eval("a = 1") df -When ``inplace`` is set to ``False``, the default, a copy of the :class:`DataFrame` with the +A copy of the :class:`DataFrame` with the new or modified columns is returned and the original frame is unchanged. .. ipython:: python df - df.eval("e = a - c", inplace=False) + df.eval("e = a - c") df As a convenience, multiple assignments can be performed by using a @@ -677,7 +674,6 @@ multi-line string. c = a + b d = a + b + c a = 1""", - inplace=False, ) The equivalent in standard Python would be diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index ee2ff030f7401..2fdd36d861e15 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -769,8 +769,7 @@ as the one being grouped. The transform function must: the first group chunk using chunk.apply. * Not perform in-place operations on the group chunk. Group chunks should be treated as immutable, and changes to a group chunk may produce unexpected - results. For example, when using ``fillna``, ``inplace`` must be ``False`` - (``grouped.transform(lambda x: x.fillna(inplace=False))``). + results. * (Optionally) operates on the entire group chunk. If this is supported, a fast path is used starting from the *second* chunk. diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 6566a1d67d1c9..de55fb4f2d63f 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1074,15 +1074,7 @@ This can be done intuitively like so: df2[df2 < 0] = 0 df2 -By default, ``where`` returns a modified copy of the data. There is an -optional parameter ``inplace`` so that the original data can be modified -without creating a copy: - -.. ipython:: python - - df_orig = df.copy() - df_orig.where(df > 0, -df, inplace=True) - df_orig +``where`` returns a modified copy of the data. .. note:: @@ -1239,18 +1231,6 @@ If instead you don't want to or cannot name your index, you can use the name the index as ``ilevel_0`` as well, but at this point you should consider renaming your columns to something less ambiguous. - -The :class:`DataFrame.query` method has a ``inplace`` keyword which determines -whether the query modifies the original frame. - -.. ipython:: python - - df = pd.DataFrame(dict(a=range(5), b=range(5, 10))) - df.query("a > 2") - df.query("a > 2", inplace=True) - df - - :class:`~pandas.MultiIndex` :meth:`~pandas.DataFrame.query` Syntax ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1616,7 +1596,7 @@ See :ref:`Advanced Indexing ` for usage of MultiIndexes. ind = pd.Index([1, 2, 3]) ind.rename("apple") ind - ind.set_names(["apple"], inplace=True) + ind = ind.set_names(["apple"]) ind.name = "bob" ind @@ -1736,14 +1716,11 @@ the given columns to a MultiIndex: frame = frame.set_index(['a', 'b'], append=True) frame -Other options in ``set_index`` allow you not drop the index columns or to add -the index in-place (without creating a new object): +Other options in ``set_index`` allow you not drop the index columns. .. ipython:: python data.set_index('c', drop=False) - data.set_index(['a', 'b'], inplace=True) - data Reset the index ~~~~~~~~~~~~~~~ diff --git a/doc/source/user_guide/missing_data.rst b/doc/source/user_guide/missing_data.rst index aefb5f0d3d2df..979c19f53bf70 100644 --- a/doc/source/user_guide/missing_data.rst +++ b/doc/source/user_guide/missing_data.rst @@ -685,12 +685,6 @@ Replacing more than one value is possible by passing a list. df.replace([1.5, df00], [np.nan, "a"]) df[1].dtype -You can also operate on the DataFrame in place: - -.. ipython:: python - - df.replace(1.5, np.nan, inplace=True) - Missing data casting rules and indexing ---------------------------------------