Skip to content Skip to sidebar Skip to footer

Python Pandas Dataframe Rounding Of Big Fraction Values

How to round off big fraction values of a pandas DataFrame.I want to round off the 'Gaps between male and female score' column of the given Dataframe image. I have tried following:

Solution 1:

Considering some initial rows of your dataframe,

YearScore01990    1.0037811992    2.3782422000    2.5130232003    2.96111

Now, if you want to round score to int, do this,

df['Score'] = df['Score'].astype(int)
df

Output:

YearScore01990    111992    222000    232003    2

And, if you want to round upto some decimal digits say upto 2-digits. Note: you can round upto as many digits as you want by passing required value to round().

df['Score'] = df['Score'].round(2)
df

Output:

YearScore01990    1.0011992    2.3822000    2.5132003    2.96

If you want to round by ceil or by floor, then use np.ceil(series) or np.floor(series) respectively.

Post a Comment for "Python Pandas Dataframe Rounding Of Big Fraction Values"