Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy roundup to nearest 5

#To roundup to nearest 5
import numpy as np
def roundup(x):
    return int(np.ceil(x / 5.0)) * 5
Comment

numpy round to nearest 5

#To round to nearest 5
import numpy as np
import pandas as pd
df
>>>
0  34.36
1  1571.80
2  12.54

np.around(df.A.values/5, decimals=0)*5
>>> array([35., 1570., 15.])
#OR 
ar = np.array([34.36, 1571.80, 12.54])
np.around(ar/5, decimals=0)*5
>>> array([35., 1570., 15.])
Comment

PREVIOUS NEXT
Code Example
Python :: Using Variables with Multiple Instances of a Python Class 
Python :: loop through list of tuples python 
Python :: how to read excel with multiple pages on pandas 
Python :: python get attributes of class 
Python :: or operator in django queryset 
Python :: python Program to check if a given year is leap year 
Python :: dataframe drop rows by column value 
Python :: where are python libraries installed in windows 
Python :: list sort by key python 
Python :: selection sort python 
Python :: date colomn to datetime 
Python :: select rows where column value is in list of values 
Python :: Return a Series containing counts of unique values. 
Python :: shutil move file 
Python :: instabot login python 
Python :: __call__ python 
Python :: dense rank in pandas 
Python :: keras linear regression 
Python :: python merge two lists alternating 
Python :: python3 strip punctuation from string 
Python :: for loop with index python3 
Python :: _getfullpathname: path should be string, bytes or os.PathLike, not list 
Python :: python get stock prices 
Python :: matplotlib custom legend 
Python :: convert array to set python 
Python :: import time in python 
Python :: python remove special characters from list 
Python :: how to start a new django project 
Python :: how to get unique value of all columns in pandas 
Python :: http server 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =