【发布时间】:2020-08-06 13:58:13
【问题描述】:
我目前有一个数据框 df
id | c1 | c2 | c3 |
1 | diff | same | diff
2 | same | same | same
3 | diff | same | same
4 | same | same | same
我希望我的输出看起来像
name| diff | same
c1 | 2 | 2
c2 | 0 | 4
c3 | 1 | 3
当我尝试时:
df.groupby('c2').pivot('c2').count() -> transformation A
|f2 | diff | same |
|same | null | 2
|diff | 2 | null
我假设我需要为每一列编写一个循环并通过转换 A 传递它? 但是我在正确转换 A 时遇到问题。 请帮忙
【问题讨论】:
-
你还有其他不同的值吗?
-
你现在可以假设没有