添加重复单词的值并将其绘制出来

问题描述 投票:1回答:2
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
python-3.x pandas count bar-chart unique
2个回答
0
投票

设置

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

0
投票

考虑以上答案,请确保您的数据不包含空格等。使用str.strip()功能将其删除,例如:

data['column'].str.strip()
© www.soinside.com 2019 - 2024. All rights reserved.