bins = [x for x in range(-10, 11)]
df['val'].plot(kind='hist', bins=bins)
I want to put all the out-range values >10 or <-10 into the boundary right/left bin but not change their widths. btw suppose the max/min value of df
is dynamic.
I can build two boundary bins like [-9999, 0]
and [0, 9999]
, but their width will be extremely large. Another way is to clip the data of df['val']
by
np.clip(df['val'], a_max= bins[-1], a_min=bins[0])
Is there an easy way to achieve my goal without change df