首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将重复单词的值相加,并绘制它们

将重复单词的值相加,并绘制它们
EN

Stack Overflow用户
提问于 2020-03-24 03:08:42
回答 1查看 20关注 0票数 1
代码语言:javascript
复制
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

如何才能唯一地打印输出,使重复单词的值相加,并且单词不重复

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2020-03-24 03:15:38

设置

代码语言:javascript
复制
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

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60820080

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档