Converting pandas series to iterable of iterables

Viewed 1277

I am trying to use MultiLabelBinarizer in sklearn. I have a pandas series and I want to feed that series as input to MultiLabelBinarizer's fit function. However, I see that MultiLabelBinarizer's fit needs an input of form iterable of iterables. I am not sure how can I convert pandas series to required type.

import pandas as pd
from sklearn.preprocessing import MultiLabelBinarizer

data = pd.read_csv("somecsvFile")
y = pd.DataFrame(data['class'])

mlb = MultiLabelBinarizer()
y = mlb.fit(???)

I tried converting it to numpy array, tried using iter function of pandas, but nothing seems to be working.

Please suggest me some way.

Thanks

Edit1: Output of print(data['class'].head(10)) is:

0        func
1        func
2        func
3    non func
4        func
5        func
6    non func
7    non func
8    non func
9        func
Name: status_group, dtype: object
2 Answers
Related