3000 explained code solutions for 75 technologies


python-pandasHow to ceil values in dataframe


import pandas as pd
import numpy as np

df = pd.DataFrame({
  'phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'price': [204.10, 304.99, 404.5, 405.5, 305.90]
})

df['price'] = df['price'].apply(np.ceil)ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.apply(

applies given callback to all values of given column (or multiple columns)

np.ceil

Numpy module ceil function


Usage example

import pandas as pd
import numpy as np

df = pd.DataFrame({
  'phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'price': [204.10, 304.99, 404.5, 405.5, 305.90]
})

df['price'] = df['price'].apply(np.ceil)
print(df)
output
  phone  price
0   ip5  205.0
1   ip6  305.0
2   ip8  405.0
3   sms  406.0
4    xi  306.0