假设我有一个 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
我将如何通过score列中的唯一值计算列中的实例term?产生如下结果:
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 计数和求和特定条件和Pandas python 中的 COUNTIF 在多个具有多个条件的列上,但似乎都不是我想要做的。pivot_table正如在这个问题中提到的,它似乎可能是相关的,但由于缺乏经验和熊猫文档的简洁性,我受到了阻碍。感谢您的任何建议。
幕布斯7119047
翻翻过去那场雪
相关分类