I'm carrying some mathematical operations on datatable fields as follows
Sample DT:
py_DT = dt.Frame({'junction' : ['BroadwayCycleTrack-N','BroadwayCycleTrack-N',
'Burke Gilman Trail','Burke Gilman Trail','Elliot Bay','Elliot Bay'],
'time_window' : ['N','MD','M','M','N','MD'],
'total_bus' :[3526,8732,6732,9821,6473,9273]
})
I would like to calculate a percentage of busses passed thorough by each junction as
Code chunk
py_DT[:,{'perc_of': f.total_bus/dt.sum(f.total_bus)},by(f.junction)]
Here a new field with a name perc_of holds the calculated value in floating numbers such as
0.287649 and 0.712351 for crossing BroadwayCycleTrack-N
Here i was trying to make use of dt.math module to get the floating numbers rounded since the F expression in DT is not allowing python's round method.
Code chunks:
py_DT[:,{'perc_of': dt.math.trunc(f.total_bus/dt.sum(f.total_bus))},by(f.junction)]
py_DT[:,{'perc_of': dt.math.floor(f.total_bus/dt.sum(f.total_bus))},by(f.junction)]
py_DT[:,{'perc_of': dt.math.ceil(f.total_bus/dt.sum(f.total_bus))},by(f.junction)]
py_DT[:,{'perc_of': dt.math.trunc(f.total_bus/dt.sum(f.total_bus))},by(f.junction)]
They are not getting worked out to round off 0.287649 to 0.28 or 0.287, is there any other function i should try for it?. i was searching for it documentation but i couldn't find an appropriate one for it.