【问题标题】:If statement on a specific cell in an Excel dataExcel 数据中特定单元格的 if 语句
【发布时间】:2021-12-05 14:04:26
【问题描述】:

我正在尝试根据 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")

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

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

【问题讨论】:

  • 改成if not pd.isna(check):
  • 干杯 Vinzent,这确实有效!我不知道 .insa,非常有帮助!
  • 知道我的脚本为什么不起作用吗?
  • 请您回答这个问题,我会接受解决方案

标签: python pandas


【解决方案1】:

文森特提供的答案

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

【讨论】:

  • 这不是文森特的答案吗?你可以让他/她写下答案,你会接受的。
猜你喜欢
  • 1970-01-01
  • 2017-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-09
相关资源
最近更新 更多