程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python:No such file or directory

編輯:Python
問題遇到的現象和發生背景

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'

我想要達到的結果

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved