python - pandas 如何检查数据框中所有列的 dtype?

标签 python pandas dataframe

dtype 似乎只对 pandas.DataFrame.Series 有效,对吧?有没有一次显示所有列的数据类型的功能?

最佳答案

singular 形式 dtype 用于检查单个列的数据类型。 plural 形式 dtypes 用于返回所有列的数据类型的数据框。本质上:

对于单列:

dataframe.column.dtype

对于所有列:

dataframe.dtypes

示例:

import pandas as pd
df = pd.DataFrame({'A': [1,2,3], 'B': [True, False, False], 'C': ['a', 'b', 'c']})

df.A.dtype
# dtype('int64')
df.B.dtype
# dtype('bool')
df.C.dtype
# dtype('O')

df.dtypes
#A     int64
#B      bool
#C    object
#dtype: object

关于python - pandas 如何检查数据框中所有列的 dtype?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40353079/

相关文章:

python - 二叉树前序遍历

来自编程集体智慧的 Python 代码

python - Pandas Rolling vs Scipy kurtosis - 严重的数值不准确

python - 将 DataFrame 导出和导入到 Access 文件 (.mdb)

python - 使用 Python 进行嵌套列提取

r - 有效地将命名列表转换为 data.frame

python - 通过从其他 DataFrame 中选择值来在 Pandas DataFrame 中填充 NaN

python - 在单个数据框中显示所有匹配对 - Python Record Linkage

python - SQLAlchemy - Mixin 与 MetaClass 修改

python - 将两个变量解压到 DataFrame 中的两列中