python-3.x - 添加重复单词的值并绘制它们
问题描述
word
steam 84
heating 9
horizontal well 4
electromagnetic 2
single well 1
steam 5
foam 2
heating 1
solvent 5
hexane 7
steam foam 1
surfactant 106
miscible 1
我怎样才能唯一地打印输出,使得重复单词的值加起来并且单词不重复
steam 89
foam 2
heating 10
horizontal well 4
solvent 5
hexane 7
electromagnetic 2
steam foam 1
surfactant 106
single well 1
miscible 1
解决方案
设置
s = pd.Series(
[84, 9, 4, 2, 1, 5, 2, 1, 5, 7, 1, 106, 1],
['steam',
'heating',
'horizontal well',
'electromagnetic',
'single well',
'steam',
'foam',
'heating',
'solvent',
'hexane',
'steam foam',
'surfactant',
'miscible']
).rename_axis('word')
s
word
steam 84
heating 9
horizontal well 4
electromagnetic 2
single well 1
steam 5
foam 2
heating 1
solvent 5
hexane 7
steam foam 1
surfactant 106
miscible 1
dtype: int64
sum
s.sum(level=0)
word
steam 89
heating 10
horizontal well 4
electromagnetic 2
single well 1
foam 2
solvent 5
hexane 7
steam foam 1
surfactant 106
miscible 1
dtype: int64
推荐阅读
- r - 计算数据框中常见的、互斥的元素
- mysql - 在 VALUES 查询中添加 SELECT 时出错
- android - 无法让我的第一个 Kotlin 协程函数工作
- python - Pandas Dataframe 保存到 CSV 更改时间列表
- excel - 如何在数据透视表中创建汇总商店收入的范围
- python - 在函数结束之前分配 Python 变量
- html - 如何缩短边框?
- postgresql - 有没有办法从“plpy.error”引发的异常中删除“plpy.Error:”前缀?
- r - lapply 和 mutate_all/for 循环
- jquery - 使用 setInterval 分别显示 MySQL 表中的随机记录