admin管理员组文章数量:1319479
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!
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")
```
本文标签:
版权声明:本文标题:python - Module not found error with docx and pandas, no output with VSCode and Terminal - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742059479a2418493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论