【发布时间】:2018-09-20 14:05:12
【问题描述】:
假设我有一个 DataFrame:
term score
0 this 0
1 that 1
2 the other 3
3 something 2
4 anything 1
5 the other 2
6 that 2
7 this 0
8 something 1
我将如何通过 term 列中的唯一值计算 score 列中的实例?产生如下结果:
term score 0 score 1 score 2 score 3
0 this 2 0 0 0
1 that 0 1 1 0
2 the other 0 0 1 1
3 something 0 1 1 0
4 anything 0 1 0 0
我在这里读到的相关问题包括Python Pandas counting and summing specific conditions 和COUNTIF in pandas python over multiple columns with multiple conditions,但似乎都不是我想要做的。 this question 中提到的 pivot_table 似乎是相关的,但由于缺乏经验和 pandas 文档的简洁性,我受到了阻碍。感谢您的任何建议。
【问题讨论】:
-
这是一个非常有用的资源,谢谢。
-
不客气 (-:
标签: python pandas dataframe pivot-table