Search code examples
python-3.xcountfrequencycpu-word

Python: Get word count frequency from a string?


Colorado!

How do I get word count frequency from a string in Python?

Steps applied -- (1) Ran getText() function to extract text from a Word document.Docx (2) Output is 500 words as a string

getText() function code
def getText(filename):
doc = docx.Document(filename)
fullText = []
for para in doc.paragraphs:
    fullText.append(para.text)
return '\n'.join(fullText)

SAMPLE DATA BUSINESS SKILLS Analytics: Data Analysis, Databases, Dashboards, Reports, Quantitative Math, Visualizations Compensation: Commissions, Consulting, Data Integrations, Salary Analysis, Sales Commissions Applications Industries: Engineering, Financial Services, Healthcare, Insurance, Real Estate, and Technology

TECHNICAL SKILLS Software: ADP, HR Cube, Channel Management, Jama Requirements Management PayScale, PeopleSoft, Salary CompAnalyst, Salesforce, SAP Business Intelligence: Power Business Intelligence (Power BI), Power Query, Tableau Programming: Python, SQL, VBA, XML
Databases: Access, MySQL, Oracle, Toad Tools: Apple, Google, Microsoft Office, Lucidchart, Slack, Smartsheet, SFTP, and Visio

WORK EXPERIENCE Developed salary database, data mappings, data mining, design analytics, reports, and dashboards. Optimized database algorithms for searching jobs and market salaries based on proprietary criteria. Communicated sales incentives plans annual changes, new enrollments, promotions, and transfers. Performed salary planning for base and variable pay, salary market pricing, salary consulting, and total rewards statements. Reconciled financial data for analysis using Excel Vlookups, Pivot Tables, Power Pivot, and Visual Basic. Normalized HRIS databases to improve data warehousing using Access, HR Cube, and SQL. Extracted data for compensation trends, forecasting, and compliance periodic reporting.

Thanks a tons for your help & sharing knowledge. -myrna


Solution

  • There are a number of good tutorials out there that cover this. I like this one as it provides some visuals that can help explain what's going on.

    The code from said tutorial (posted here for convenience):

    def word_count(str):
        counts = dict()
        words = str.split()
    
        for word in words:
            if word in counts:
                counts[word] += 1
            else:
                counts[word] = 1
    
        return counts
    
    print( word_count('the quick brown fox jumps over the lazy dog.'))