Python Forum
Word count in loop - .exc file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Word count in loop - .exc file
#1
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.
Reply
#2
bagsofwords = []
while i < 75:
    # more code
    bagsofwords.append( your_collection )
99 percent of computer problems exists between chair and keyboard.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020