Is there any way to access the limit values when using bins with value_counts(). For example from:
'(105.004, 133.322] 75'
'(48.368, 76.686] 74'\
to extract the values 105.004 & 133.332 and so on...
CodePudding user response:
Try:
out = df['col'].value_counts(bins=2)
values = [(vals.left, vals.right) for vals in out.index.to_numpy()]
print(values)
print(out)
# Output
[(1.997, 3.0), (3.0, 4.0)]
(1.997, 3.0] 4
(3.0, 4.0] 1
Name: col, dtype: int64
Setup:
df = pd.DataFrame({'col': [2, 4, 2, 3, 3]})
print(df)
# Output
col
0 2
1 4
2 2
3 3
4 3
