python - 访问数据框中的列以通过 for 循环验证 dtype 时出现 AttributeError
问题描述
我正在尝试替换数据框中的 nan ,因此我需要访问 float 或 integers 列:它可以在不使用 for 循环的情况下工作
for col in df:
if(df.col.dtype!="object"):
aux=df[col].mean()
df[col].fillna(aux,inplace=True)
我得到的错误:
AttributeError:“DataFrame”对象没有属性“col”
解决方案
正确的语法是df[col].dtype
推荐阅读
- spring-boot - 为什么无法使用 thymleaf 和 Spring boot 向网页显示图像?
- mysql - SpringBoot应用程序与mysql数据库连接给出连接错误
- java - 当 Spring 执行器在 Webflux 项目中遇到 Spring Metrics 时
- javascript - 使用 Typescript 允许 React 组件上的任意 data-* 属性
- c++ - C++ / Arduino:如何从子类访问对象
- c# - 为什么 asp .net core 不在异步方法中记录异常?
- ios - 通过 Flutter 解析 OneSingal 推送通知中的附加数据
- spring - Spring Boot 应用程序。批处理在 JpaRepository.saveAll 方法中不起作用
- java - 从 0.5.0 到 0.8.0 的 opentelemetry-api 迁移问题
- javascript - Spring Boot:双引号格式错误