0

I'm using Docx and Pandas to create a program that copies data from an Excel sheet to a Word document. I've been running into some errors in VSCode, where I am either thrown a ModuleNotFound error with pandas and docx, or I am given no output with my program. I am assuming there is an issue with how I'm running something, but I can not find it. It would be greatly appreciated if someone could let me know why there is no output, as well as why I am randomly thrown this error.

For reference, my pip list shows that docx and pandas are both installed and up to date.

I am also looking for a better way to code this! All help is greatly appreciated!

pip list error message

import pandas as pd
from docx import Document
def assignteam(spreadsheet, tabname, teamnum):
    df = pd.read_excel(spreadsheet, sheet_name=tabname)

    check_team = df[df["Team Name"] == teamnum]
    print("hello i work")

    return check_team 
print("hello i work")
def one_pager(check_team, teamnum):
    doc = Document()
    doc.add_heading(f'Team {teamnum} Data', level=1)
    table = doc.add_table(rows = 1, cols = len(check_team.columns)) 
    table.style = 'Table Grid'
    print("hello i work")

    
    header = table.rows[0].cells 
    for x, col in enumerate(check_team.columns):
        header[x].text = str(col)
    print("hello i work pt2")

    
    for index, row in check_team.iterrows(): 
        cells = table.add_row().cells
        for x, value in enumerate(row):
            cells[x].text = str(value)
    print("hello i work pt3")

    doc.save(f'Team_{teamnum}.docx') 

def main():
    # Self-explanatory
    spreadsheet = input("Enter the path to the spreadsheet: ") 
    tabname = input("Enter the tab name: ")
    teamnum = input("Enter team number: ")

    totaldat = assignteam(spreadsheet, tabname, teamnum)
    
    if totaldat.empty:
        print(f"No data found for team {teamnum}.")
    else:
        one_pager(totaldat, teamnum)
        print(f"Data for team {teamnum} has been written to Team_{teamnum}.docx")
    ```
3
  • 2
    Are you sure that the python that VSCode is using is the exact same one that you have pip installed to? Commented Jan 19 at 21:19
  • 2
    And before you say "yes", I want you to edit the question to show the output of three things: python -m pip -V, pip -V, and which interpreter you have selected in VSCode Commented Jan 19 at 21:21
  • Any updates? Have you tried cleaning the workspace? Commented Jan 22 at 6:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.