Word count in loop - .exc file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Word count in loop - .exc file (/thread-6741.html) |
Word count in loop - .exc file - martinqwert - Dec-05-2017 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. RE: Word count in loop - .exc file - Windspar - Dec-05-2017 bagsofwords = [] while i < 75: # more code bagsofwords.append( your_collection ) |