def test_dataframe_dummies_with_categorical(self):
df = self.df
df['cat'] = pd.Categorical(['x', 'y', 'y'])
result = get_dummies(df, sparse=self.sparse)
expected = DataFrame({'C': [1, 2, 3],
'A_a': [1., 0, 1],
'A_b': [0., 1, 0],
'B_b': [1., 1, 0],
'B_c': [0., 0, 1],
'cat_x': [1., 0, 0],
'cat_y': [0., 1, 1]})
expected = expected[['C', 'A_a', 'A_b', 'B_b', 'B_c', 'cat_x', 'cat_y'
]]
assert_frame_equal(result, expected)
# GH12402 Add a new parameter `drop_first` to avoid collinearity
test_reshape.py 文件源码
python
阅读 36
收藏 0
点赞 0
评论 0
评论列表
文章目录