Python The small white , One is due at the end of this term python Homework , But the following problems occur repeatedly when writing good code , Please answer me .
import pandas as pd
import numpy as np
# Eliminate the records with empty treatment method
df = pd.read_excel(" Data table _25.xlsx", sheet_name=" Formulas and functions ", index_col=False)
df.dropna()
df.to_excel(" Data table _25_2.xlsx", sheet_name=" Formulas and functions ")
# Calculate the average number of days of medication corresponding to different treatment methods
df = pd.read_excel(" Data table _25.xlsx", sheet_name=" Formulas and functions ", 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(" The treatment method is P1 The average days of administration were :", int(mean_P1/count_P1))
print(" The treatment method is M1 The average days of administration were :", int(mean_M1/count_M1))
Traceback (most recent call last):
File "C:\pythonProject\main.py", line 5, in
df = pd.read_excel(" Data table _25.xlsx", sheet_name=" Formulas and functions ", 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: ' Data table _25.xlsx'