Python: Pandas.cut Labels Are Ignored
I want to cut one column in my pandas.DataFrame using pandas.cut(), but the labels I put into labels argument are not applied. Let me show you an example. I have got the following
Solution 1:
It is bug issue 21233.
For me working like @anky_91 commented mapping by dictionary created by zip
:
df['x_cut'] = pd.cut(df['x'], bins).map(dict(zip(bins, labels)))
print(df)
x x_cut
0 -0.009 200
1 0.089 300
2 0.095 300
3 0.096 300
4 0.198 400
Post a Comment for "Python: Pandas.cut Labels Are Ignored"