我在运行代码时遇到了麻烦。我希望通过使用csv文件pandas (docs)的名称调用read_csv()方法read_csv()来加载“森林火灾”数据集,并将结果存储在变量forestfire_df中。
解释器一直抛出此错误。
name 'forestfire_df' is not defined".这是我的代码:
import numpy as np
import pandas as pd
if not os.path.exists("forestfires.csv"):
raise Exception(f"The forestfires.csv is not detected in your local path! " \
f"You need to move the 'forestfires.csv' file to the same " \
f"location/directory as this notebook which is {os.getcwd()}")
# TODO 1.1
display(forestfire_df)
display(pd.read_csv("forestfires.csv"))
([
(np.all(forestfire_df.iloc[0].values == np.array([7, 5, 'mar', 'fri', 86.2, 26.2, 94.3, 5.1, 8.2, 51, 6.7, 0.0, 0.0],
dtype=object)), '')
])有人知道怎么解决这个问题吗?
发布于 2022-12-01 22:11:22
在显示forestfire_df之前,必须定义它,例如,使用如下一行:
forestfire_df = pd.read_csv("forestfires.csv")https://stackoverflow.com/questions/74648703
复制相似问题