Reputation: 3502
Can someone give me a tip if its possible to round to the nearest integer value of 5 or 10.
My data looks like this:
Date_Time kW
0 2011-03-01 00:15:00 171.36
1 2011-03-01 00:30:00 181.44
2 2011-03-01 00:45:00 175.68
3 2011-03-01 01:00:00 180.00
And I am wanting to round the kW
column to the nearest 5 or 10 kW value.
df = df.round({'rollingKw':0})
This gets me to the nearest integer but I would like to round to the nearest 5 or 10 kW to reduce the resolution in plotting my dataset.
Upvotes: 3
Views: 111
Reputation: 323226
Check with this (floor round)
df.kW//5*5
Out[175]:
0 2011-03-01 170.0
1 2011-03-01 180.0
2 2011-03-01 175.0
3 2011-03-01 180.0
Name: kW, dtype: float64
Or if you want the nearest
(df.kW/5).round().mul(5).astype(int)
0 2011-03-01 170
1 2011-03-01 180
2 2011-03-01 175
3 2011-03-01 180
Upvotes: 3