One of my columns in pandas dataframe looks like following. I would like to bin my "Daughter" column such that row with 0 will receive label of "None" and rows containing 1,2,3,4 will receive labels of "Some".
Current Dataset that contains column
Daughter
0
0
1
2
4
3
Expected Output:
Daughter Daugther_fact
0 None
0 None
1 Some
2 Some
4 Some
3 Some
I new newbie to python. I know I have to use pd.cut to assign my labels, but I am not sure how to achieve this. Any help is appreciated!
Is this what you need ?
pd.cut(df.Daughter,[-np.inf,0,np.inf],labels=['None','some'])
Out[35]:
0 None
1 None
2 some
3 some
4 some
5 some
Name: Daughter, dtype: category
Categories (2, object): [None < some]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With