首页 > 解决方案 > Excel 数据中特定单元格的 if 语句

问题描述

我正在尝试根据 excel 数据框中的单元格值运行特定的脚本行。如果特定单元格不为空,我基本上想进行计算。为此,我使用了以下代码:

check=df.iat[1,13]  #I am reading the value of the cell

if check is not (None, "[nan]"):
    print("cell is not empty")

当我打印检查的值(单元格值)时,我得到'nan'。但是,if 语句不起作用,因为没有打印任何内容。

我不确定为什么会发生这种情况,我将不胜感激任何提示。谢谢!

标签: pythonpandas

解决方案


文森特提供的答案

check=df.iat[1,13]  #I am reading the value of the cell
if not pd.isna(check):
    print("cell is not empty")


推荐阅读