for cat in col.cat.categories[1:]:
expected_cat["{}={}".format(nam, cat)] = pd.Series(
col == cat, dtype=np.float64)
expected_cat = pd.DataFrame(expected_cat)
expected_data = pd.concat((data.drop(dat_cat, axis=1), expected_cat), axis=1)
return expected_data
After Change
def encoded_data(data):
expected = []
for nam, col in data.iteritems():
if hasattr(col, "cat"):
for cat in col.cat.categories[1:]:
name = "{}={}".format(nam, cat)
s = pd.Series(col == cat, dtype=np.float64)
expected.append((name, s))
else:
expected.append((nam, col))
expected_data = pd.DataFrame.from_items(expected)
return expected_data
class TestOneHotEncoder(TestCase):