问题遇到的现象和发生背景
Python小白,这学期末要交一个python作业,但是写好代码反复出现以下问题,求大佬解答。
问题相关代码,请勿粘贴截图
import pandas as pd
import numpy as np
#剔除治疗方式为空的记录
df = pd.read_excel("数据表格_25.xlsx", sheet_name="公式与函数", index_col=False)
df.dropna()
df.to_excel("数据表格_25_2.xlsx", sheet_name="公式与函数")
#计算不同治疗方式对应的用药天数的均值
df = pd.read_excel("数据表格_25.xlsx", sheet_name="公式与函数", index_col=False)
mean_M1 = 0
count_M1 = 0
mean_P1 = 0
count_P1 = 0
for i in df.index:
each_record = df.values[i]
if each_record[3] == "M1":
mean_M1 += each_record[4]
count_M1 += 1
if each_record[3] == "P1":
mean_P1 += each_record[4]
count_P1 += 1
print("治疗方式为P1的平均用药天数为:", int(mean_P1/count_P1))
print("治疗方式为M1的平均用药天数为:", int(mean_M1/count_M1))
运行结果及报错内容
Traceback (most recent call last):
File "C:\pythonProject\main.py", line 5, in
df = pd.read_excel("数据表格_25.xlsx", sheet_name="公式与函数", index_col=False)
File "C:\Users\DELL\AppData\Roaming\Python\Python39\site-packages\pandas\util_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "C:\Users\DELL\AppData\Roaming\Python\Python39\site-packages\pandas\io\excel_base.py", line 457, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "C:\Users\DELL\AppData\Roaming\Python\Python39\site-packages\pandas\io\excel_base.py", line 1376, in init
ext = inspect_excel_format(
File "C:\Users\DELL\AppData\Roaming\Python\Python39\site-packages\pandas\io\excel_base.py", line 1250, in inspect_excel_format
with get_handle(
File "C:\Users\DELL\AppData\Roaming\Python\Python39\site-packages\pandas\io\common.py", line 798, in get_handle
handle = open(handle, ioargs.mode)
FileNotFoundError: [Errno 2] No such file or directory: '数据表格_25.xlsx'