python - 如何在 Pandas 中找到数字列?

标签 python types pandas

假设 df 是一个 pandas DataFrame。 我想找到所有数字类型的列。 比如:

isNumeric = is_numeric(df)

最佳答案

您可以使用 DataFrame 的 select_dtypes 方法。它包括两个参数 include 和 exclude。所以 isNumeric 看起来像:

numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']

newdf = df.select_dtypes(include=numerics)

关于python - 如何在 Pandas 中找到数字列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25039626/

相关文章:

python - Pandas 根据列计算顺序

python - 如何通过 Pandas 中的星期几开始按日期时间列分组

c++ - 字段的类型不完整 : int*[]

python - 使用字符串列表按列标签对 Pandas DataFrame 进行切片

python - 安装没有 Chameleon 的 Pyramid

python - 如何获取包含特定 dtype 的 pandas.DataFrame 列

python - 尝试在 python : invalid dsn: invalid connection option "username" 中连接时出现 PostgreSQL 错误

java - 哪些Python模块将有效利用多核处理大量传入消息

types - OCaml 联合类型

go - 保存类型以供以后反射