df A 0 503.36 1 509.80 2 612.31 3 614.29
I want to round to the nearest 5 in a new column B using numpy if possible.
The conclusion should be:
A B 0 503.36 505.00 1 509.80 510.00 2 612.31 610.00 3 614.29 615.00
Since you mention numpy
numpy
np.around(df.A.values/5, decimals=0)*5 Out[31]: array([505., 510., 610., 615.])
You can use:
df['B'] = df.div(5).round(0) * 5
Or as @piRSquared state:
df['B'] = df['A'].mul(2).round(-1).div(2)
Conclusion:
A B 0 503.36 505.0 1 509.80 510.0 2 612.31 610.0 3 614.29 615.0
df.assign(B=df.mul(2).round(-1).div(2)) A B 0 503.36 505.0 1 509.80 510.0 2 612.31 610.0 3 614.29 615.0
Source: https://habr.com/ru/post/1694867/More articles:Export PDF, CSV, Excel form datatable using jquery? - jqueryСписок групп каталога Google Admin для электронной почты пользователя возвращает неверный пустой ответ - directoryKivy: Как начать текст с правой стороны в TextInput? - pythonHow to limit the size of a multi-page file in a java controller - javanode - fs.readdir does not work in files with special characters - javascriptIf immutable final variables are always static? - javaPartial intersection of elements over vectors in two lists - listBest algorithm for converting a real number from 0 to 1 to an index - pythonhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1694871/how-to-check-if-a-symlink-not-the-file-it-points-to-exists-in-rust&usg=ALkJrhhc4jV4_htbnVrCqMM80Ws1l4Fp4wThe most idiomatic way to create a cyclic and infinite range of integers in Java 8 - java-8All Articles