pandas 如何检查数据框中所有列的dtype? [英] pandas how to check dtype for all columns in a dataframe?

查看:65
本文介绍了 pandas 如何检查数据框中所有列的dtype?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎dtype仅适用于pandas.DataFrame.Series,对吗?是否可以同时显示所有列的数据类型?

It seems that dtype only work for pandas.DataFrame.Series, right? Is there a function to display data types of all columns at once?

推荐答案

单数形式的dtype用于检查单个列的数据类型. 复数 表单dtypes用于数据框架,该框架返回所有列的数据类型.本质上:

The singular form dtype is used to check the data type for a single column. And the plural form dtypes is for data frame which returns data types for all columns. Essentially:

对于单个列 :

For a single column:

dataframe.column.dtype

对于所有列 :

For all columns:

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

这篇关于 pandas 如何检查数据框中所有列的dtype?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆