make_table()在iPython(Jupyter)中的if-else语句中不起作用
我正在使用os.path.exists()检查文件是否存在,如果存在,我想显示该表,该表包含使用数据帧从csv文件收集的信息,但是当我在if else语句中写入make_table()时,它不会显示其内容,但每当我在外部写入时,它都会显示数据。这种情况不应该发生,因为如果文件存在,我希望显示数据。请看下面我的代码make_table()在iPython(Jupyter)中的if-else语句中不起作用,python,ipython,jupyter-notebook,Python,Ipython,Jupyter Notebook,我正在使用os.path.exists()检查文件是否存在,如果存在,我想显示该表,该表包含使用数据帧从csv文件收集的信息,但是当我在if else语句中写入make_table()时,它不会显示其内容,但每当我在外部写入时,它都会显示数据。这种情况不应该发生,因为如果文件存在,我希望显示数据。请看下面我的代码 import pandas from ipy_table import * ... save_path = select_season(season) name_of_file =s
import pandas
from ipy_table import *
...
save_path = select_season(season)
name_of_file =select_league(league)
filename = save_path + name_of_file +".csv"
new_df_home = df[df.FTR == 'H']
new_df_away = df[df.FTR == 'A']
new_df_draw = df[df.FTR == 'D']
if os.path.exists(filename):
df = pd.read_csv(os.path.join(save_path, name_of_file+".csv"))
Matches = [
['Matches Played', 'Home Wins', 'Draws', 'Away Wins','Full time Home goals', 'Full time Away goals',
'Half time Home goals', 'Half time Away goals'],
[df['Div'].count(), new_df_home['Div'].count(), new_df_draw['Div'].count(), new_df_away['Div'].count(),df['FTHG'].sum(),
df['FTAG'].sum(),df['HTHG'].sum(),df['HTAG'].sum()]];
make_table(Matches)
else:
print("This record is not present")
您可能需要存储make_表的结果(匹配项): 并以以下内容结束您的代码:
...
else:
print("This record is not present")
table
因此,该表将在末尾打印…您是否检查了if分支是否执行?例如,在创建数据帧后使用print语句?是的,我在if branch中编写了print(1)并执行代码,它将打印1。因此,它将进入if分支,但不执行make_table(Matches)
...
else:
print("This record is not present")
table