Trying to find a way to do a sum of all the columns (there are around 7) with the criteria being 1 word? For example, across all the columns of Name, Fruit, Country, etc. I want to know how many times the word 'the' appears in each one.
I can use this df3['Name'].str.count('The').sum(), and that will give this result:
Out[121]: 3522
But then when I add in the next string field so that it is
df3['Name'].str.count('The').sum()
df3['Fruit'].str.count('The').sum()
it only shows the last syntax (as expected):
Out[122]:27
What I obviously want is for it to say:
Name: 3522
Fruit: 27
But I don't seem to be able to use str.count or str.contains in a way that groups it like I need.
If the data is something like the following:
Name | Year | Score | 2nd Score | % of People | Country | Fruit | Export Countries | Language | Transit Duration | Quality | Taste | Freshness | Packaging
Andes, The | 2021 | 8 | 8.8 | 87% | The Netherlands | The Apple | United States,United Kingdom | English,Japanese,French | 148.0 | 1.0 | 0.0 | 0.0 | 0.0
Phil | 2021 | 8 | 8.4 | 87% | Spain | The Banana | United Kingdom, Germany | English,German,French,Italian | 165.0 | 1.0 | 0.0 | 0.0 | 0.0
Sarah | 2021 | 9 | 8.3 | 89% | Greece | The Plum | Germany,United States | English,German,French,Italian | 153.0 | 1.0 | 0.0 | 0.0 | 0.0
The expected output should be
Name: 1
Year: 0
Score: 0
2ndScore: 0
Country: 1
Fruit: 3
TransitDuration: 0
Quality: 0
Taste: 0
Freshness: 0
Packaging: 0