How to convert a particular column into binary values

Hi
I want to know how can I convert a particular column of pandas data frame into it’s binary values using LabelEncoder (from sklearn.preprocessing import LabelEncoder).
I opened Train data set as a pandas data frame, for my model the ‘label’/output values should be in binary(0&1). So I sliced label column from pandas data frame as k=df_train.loc[:,‘label’], where k is the whole pandas data frame of Train data. And then I tried doing :
from sklearn.preprocessing import LabelEncoder
le=LabelEncoder()
output=k.apply(le.fit_transform)

but it gave me a value error, I tried figuring this out but I’m unable to convert label column to binary by extracting label column from pandas data frame. Please help me out.
Thank You

I was able to train BernoulliNB model without converting label values to binary… Although I have submitted predictions for this challenge but it would be great if you still clear my doubt maybe I require this concept later on in some other problem…

hey @pasta ,
I didn’t get what actually you want to do.
Based on what i understood :
just do k = df_train[ [‘label’] ] to fit into LabelEncoder. You can also use pd.factorize for this task.

I hope this was the actual thing you wanted .
Thank You :slightly_smiling_face:.

I made a small mistake while explaining my question, correction in sentence:“So I sliced label column from pandas data frame as k=df_train.loc[:,‘label’], where df_train is the whole pandas data frame of Train data”

but it’s all right I have understood what you are trying to explain… Thank You

That’s the main thing to be done.

I hope you doubt is ore resolved. So i would request you to kindly mark this doubt as resolved and also provide your valuable feedback.
If still there is something left to discuss then you can re-raise this doubt or raise another new doubt.

Thank You :slightly_smiling_face:.