【问题标题】:'DataFrame' object has no attribute 'isna''DataFrame' 对象没有属性 'isna'
【发布时间】:2020-04-15 16:29:18
【问题描述】:

我已经为我的一个项目调整了一个机器学习代码。在我的笔记本电脑上运行良好的代码现在在我的桌面上出现问题。我正在检查所有数据框列是否存在缺失值。

  File "g100.py", line 11, in <module>
    print(dfs.columns[dfs.isna().any()].tolist()) 
AttributeError: 'DataFrame' object has no attribute 'isna'

我安装的 panda 版本和依赖项

d.show_versions(as_json=False)

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-37-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.20.3
pytest: 3.4.2
pip: 9.0.3
setuptools: 38.5.1
Cython: None
numpy: 1.11.3
scipy: 0.19.0
xarray: None
IPython: 6.2.1
sphinx: None
patsy: 0.5.0
dateutil: 2.6.0
pytz: 2017.3
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.2
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.9
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
pandas_gbq: None
pandas_datareader: 0.6.0

我可以找到为什么 isna 给我一个 AttributeError 的解释。

【问题讨论】:

  • .notna() 会出现同样的问题

标签: python pandas


【解决方案1】:

如果你比较0.20 documentation for "Working with missing data"that of 0.22,你可以看到前者使用isnull,而后者使用isna

事实上0.22 documentation for isnull 状态

isna 的别名

因此,对于您的版本,请尝试isnull

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 2021-07-14
    • 2013-10-23
    • 2017-10-22
    • 2021-01-08
    相关资源
    最近更新 更多