我有一个数据帧
column_one columnn_two type column_three
apple headphones one yes
apple headphones two yes
apple tv one no
apple iPhones two yes
apple iPad one no
apple iPad two no
我想把他们分成几行,然后数到
column_one columnn_two yes no
apple headphones 2 0
apple tv 0 1
apple iPhones 1 0
apple iPad 0 2
我知道如何进行groupby,但不知道如何计算多行并将行转换为列以获得计数
可能不是最有效的方法,但可能仍然有帮助:-)
我通过
apply()
使用了一个定制的聚合函数sum_col_three(x)
,并通过to_frame()
将结果转换为一个新的列。之后,我用新的DataFrame
和tolist()
将元组拆分为两个独立的列:相关问题 更多 >
编程相关推荐