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'