Ceil and floor of the dataframe in pandas python – Round up and Truncate

Ceil and floor of the dataframe in pandas python gets the rounded up and truncated values of column.  Let’s see how to

  • Get the ceil of column in pandas dataframe.
  • Get the floor of column in pandas dataframe.

First lets create the dataframe

import pandas as pd
import numpy as np

#Create a DataFrame
df1 = {
    'Subject':['semester1','semester2','semester3','semester4','semester1',
               'semester2','semester3'],
   'Score':[62.7,47.7,55.6,74.6,31.5,77.3,85.4]}

df1 = pd.DataFrame(df1,columns=['Subject','Score'])
print(df1)

so the resultant dataframe will be

Ceil and floor of the dataframe column in pandas python 1

 

Get the ceil of column in pandas dataframe:

Ceil gets the rounded up values of column in dataframe

df1['score_ceil'] = df1['Score'].apply(np.ceil)
print(df1)

so the resultant dataframe will be

Ceil and floor of the dataframe in pandas python - Round up and Truncate - image Ceil-and-floor-of-the-dataframe-column-in-pandas-python-2 on http://www.datasciencemadesimple.com

 

Get the floor of column in pandas dataframe:

floor gets the rounded down (truncated) values of column in dataframe

df1['score_floor'] = df1['Score'].apply(np.floor)
print(df1)

so the resultant dataframe will be

Ceil and floor of the dataframe in pandas python - Round up and Truncate - image Ceil-and-floor-of-the-dataframe-column-in-pandas-python-3 on http://www.datasciencemadesimple.com

 

Ceil and floor of the dataframe in pandas python - Round up and Truncate                                                                                                                Ceil and floor of the dataframe in pandas python - Round up and Truncate