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?

  • 1
    $\begingroup$ Yes, you need one binary column per feature. Creating a few dozen columns is usually not a problem. $\endgroup$
    – Louic
    Jul 7, 2019 at 13:02
  • $\begingroup$ Great, thanks. How do I go about this with pandas? $\endgroup$
    – Greg Rosen
    Jul 7, 2019 at 13:04

1 Answer 1


This might Pandas convert a column of list to dummies.

You can try using the MultiLabelBinarizer class from sklearn.

  • $\begingroup$ Pretty sweet solution. $\endgroup$ Jul 8, 2019 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.