Python - 获取列的数据类型
要获取列的数据类型,请使用info()方法。让我们首先导入所需的库-
import pandas as pd
创建一个具有2列具有不同数据类型的DataFrame-
dataFrame = pd.DataFrame(
{
"Student": ['Jack', 'Robin', 'Ted', 'Marc', 'Scarlett', 'Kat', 'John'],"Roll Number": [ 5, 10, 3, 8, 2, 9, 6]
}
)获取有关数据类型的完整信息-
dataFrame.info()
示例
以下是完整的代码-
import pandas as pd
#创建数据帧
dataFrame = pd.DataFrame(
{
"Student": ['Jack', 'Robin', 'Ted', 'Marc', 'Scarlett', 'Kat', 'John'],"Roll Number": [ 5, 10, 3, 8, 2, 9, 6]
}
)
print"DataFrame ...\n",dataFrame
print"\nInfo and the datatypes of the columns in the dataframe:\n"
#获取数据类型信息
print(dataFrame.info())输出结果这将产生以下输出-
DataFrame ... Roll Number Student 0 5 Jack 1 10 Robin 2 3 Ted 3 8 Marc 4 2 Scarlett 5 9 Kat 6 6 John Info and the datatypes of the columns in the dataframe:RangeIndex: 7 entries, 0 to 6 Data columns (total 2 columns): Roll Number 7 non-null int64 Student 7 non-null object dtypes: int64(1), object(1) memory usage: 184.0+ bytes None
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短