Skip to content

ENH: round(inplace=True) #35786

@Peters-D

Description

@Peters-D

Is your feature request related to a problem?

I frequently round numerical columns in my dataframe to two decimals using pandas.DataFrame.round. I would like to do this inplace, since it will make code simpler and presumable less prone to errors.

Describe the solution you'd like

DataFrame.round should get a new argument inplace such that if True the operation is done inplace. I think DataFrame.apply could also improve from this enhancement.

Example code

import pandas as pd
import numpy as np

df = pd.DataFrame({"foo": [1.11, 2.22, 3.33, 4.44, 5.55],
                   "bar": [6.66, 7.77, 8.88, 9.99, np.nan]})

# e.g. dropna() works with inplace
df.dropna(inplace=True)

# but round() does not
df["foo"] = df["foo"].round(1)

# I would like a feature like:
df["foo"].round(1, inplace=True) # does not run

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions