# Converting a Pandas Series string of multiple attributes into individual attributes?

I'm working on an Airbnb dataset in order to predict the nightly price--where each example is one Airbnb listing (ie a listing for someone's house, room, apartment, etc). Each feature is a characteristic of the listing (ie # bedrooms, # bathrooms, average review score etc).

One of the features is 'amenities', which are the amenities offered for the listing (ie wifi, tv, kitchen, etc). Each example contains a string of its own amenities like so:

{TV,"Cable TV",Wifi,"Air conditioning",Kitchen,Elevator,Heating,Washer,Dryer,"Smoke detector","Fire extinguisher",Essentials,Shampoo,Hangers,"Hair dryer",Iron,"Laptop friendly workspace","Self check-in",Keypad,"Private living room","Hot water","Bed linens",Microwave,"Coffee maker",Refrigerator,Dishwasher,"Dishes and silverware","Cooking basics",Oven,Stove,"Long term stays allowed"}


Dtype is a string ('O' in pandas).

I plan to remove the {} on the ends and the " quote signs using pd.Series.str.replace() for each character--unless those are useful to keep.

But past that I'm not sure of the best way to go about handling the feature itself.

My questions is:

Should I create individual binary columns for each amenity (ie 1 in column "TV" if TV is an amenity, 0 in column "wifi" if wifi isn't offered)? I'm hesitant because that would add a few dozen columns. If I should do this, how can I convert the current format to binary columns with Pandas?

• Yes, you need one binary column per feature. Creating a few dozen columns is usually not a problem. Jul 7, 2019 at 13:02
You can try using the MultiLabelBinarizer class from sklearn.