Добавить значения повторяющихся слов и построить их - PullRequest
1 голос
/ 23 марта 2020
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

1 Ответ

1 голос
/ 23 марта 2020

Настройка

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
...