我正在尝试为具有行中文本数据的变量创建虚拟变量。
第一行的数据是:
{"Wireless Internet","Air conditioning",Kitchen,Heating,"Family/kid friendly",Essentials,"Hair dryer",Iron,"translation missing: en.hosting_amenity_50"}
第二行的数据是:
{TV,"Cable TV",Internet,"Wireless Internet",Kitchen,"Indoor fireplace","Buzzer/wireless intercom",Heating,Washer,Dryer,"Smoke detector","Carbon monoxide detector","First aid kit","Fire extinguisher",Essentials}等等。
我现在想做的是,从该变量中创建虚拟变量。例如,从上面的数据中:
一个以行中的 ans 命名的变量和Wireless Internet另一个0以行
和行命名的变量以及另一个以行和行命名的
变量,依此类推。 1Cable TV01Kitchen01
sklearn对于 python 具有OneHotEncoder创建虚拟变量的类,它考虑到所有具有唯一值的行,连续命名所有内容。这不是我想在这里做的。我首先必须拆分所有行中的文本并为它们创建虚拟变量。我怎么做?
预期的结果是,多列,如
Wireless Internet Cable TV Kitchen
1 0 1
0 1 1
1 0 1
链接到数据(列名amenities) - https://www.kaggle.com/stevezhenghp/airbnb-price-prediction