根据分组依据数据从类别创建新列

时间:2020-09-10 08:21:33

标签: python pandas

我有奔跑 df.groupby('position')['Category'].value_counts() 我得到下面的o / p:

    Categories  Count
val1    Cat_1   1
val2    Cat_2   3
        Cat_3   2
val3    Cat_3   1
val4    Cat_2   1
val5    Cat_1   2

我想像下面那样用熊猫重建输出

Positions   Cat_1   Cat_2   Cat_3
val1           1        0       0
val2           0        3       2
val3           0        0       1
val4           0        1       0
val5           2        0       0

1 个答案:

答案 0 :(得分:2)

Series.unstack1> processfileparser.cpp(466) : see reference to function template instantiation 'SequenceT boost::algorithm::replace_first_copy<const char*,const char[7],std::string>(const SequenceT &,Range1T (&),const Range2T &)' being compiled 参数一起使用:

fill_value=0