【问题标题】:why 'NoneType' object has no attribute 'head'为什么'NoneType'对象没有属性'head'
【发布时间】:2021-09-05 23:46:33
【问题描述】:
df_new=df.fillna(0, inplace=True)
print(df_new.head(10))

为什么会显示 AttributeError: 'NoneType' object has no attribute 'head'

【问题讨论】:

  • 如果你使用inplace那么操作是就地执行,意味着它不会返回任何东西。
  • 这能回答你的问题吗? Understanding inplace=True

标签: python nonetype


【解决方案1】:

inplace=True 使其直接修改原始数据框。

所以你要么不这样做,比如:

df_new = df.fillna(0)
print(df_new.head(10))

或者直接保留为df:

df.fillna(0, inplace=True)
print(df.head(10))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多