floor

Round list values with list comprehension including None

Round list values with list comprehension including None Question: I want to round down values of a list ignoring None. Given a list without None values I would do it like: import math value_list = [1.5, 2.3, 3.2, 4.7] rounded_list = [math.floor(elem) for elem in value_list] A list including None values gives an error: import …

Total answers: 3

floor and ceil with number of decimals

floor and ceil with number of decimals Question: I need to floor a float number with an specific number of decimals. So: 2.1235 with 2 decimals –> 2.12 2.1276 with 2 decimals –> 2.12 (round would give 2.13 which is not what I need) The function np.round accepts a decimals parameter but it appears that …

Total answers: 4

Floor or ceiling of a pandas series in python?

Floor or ceiling of a pandas series in python? Question: I have a pandas series series. If I want to get the element-wise floor or ceiling, is there a built in method or do I have to write the function and use apply? I ask because the data is big so I appreciate efficiency. Also …

Total answers: 5

Taking the floor of a float

Taking the floor of a float Question: I have found two ways of taking floors in Python: 3.1415 // 1 and import math math.floor(3.1415) The problem with the first approach is that it return a float (namely 3.0). The second approach feels clumsy and too long. Are there alternative solutions for taking floors in Python? …

Total answers: 6