✒️
Here are my favorite tips to land the software engineer interview.
Here are my favorite tips to land the software engineer interview.
How to Round All Column Values to Two Decimal Places in Pandas
Published Dec 7, 2021
∙ Updated May 2, 2022
How can we force two decimal places in a DataFrame column?
Example scenario
Suppose we’re dealing with a DataFrame df
that looks something like this.
A B
0 0.1111 0.22
1 0.3333 0.44
We want only two decimal places in column A
.
A B
0 0.11 0.22
1 0.33 0.44
Force two decimal places
We can force the number of decimal places using round()
.
df['A'] = df['A'].round(2)