Python Forum

Full Version: Word count in loop - .exc file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I want to create a word count for an excel file, for cells A2-A77 (the column header A1 is named "A").
I want the cells to be word-counted separately thus I thought of using a while loop and bagsofwords.
This is what I came up with.

import pandas as pd
excel="FILE PATH"
df = pd.read_excel(excel)

i=0
while i<75:
    i=i+1
    
    import collections, re
    bagsofwords = [ collections.Counter(re.findall(r'\w+', df.at[i,'A']))]
bagsofwords[:]
Clearly, it does not work. It seems to always word-count just the last cell (in this case its A77).
Could you help me out? I am a complete novice.
bagsofwords = []
while i < 75:
    # more code
    bagsofwords.append( your_collection )