首页 > 编程语言 > 详细

Python机器学习(八十六)Pandas 数据集信息

时间:2020-06-21 22:06:34      阅读:77      评论:0      收藏:0      [点我收藏+]

info

使用.info方法,可以查看数据集的基本信息:

movies_df.info()

输出

<class pandas.core.frame.DataFrame>
Index: 1000 entries, Guardians of the Galaxy to Nine Lives
Data columns (total 11 columns):
Rank                  1000 non-null int64
Genre                 1000 non-null object
Description           1000 non-null object
Director              1000 non-null object
Actors                1000 non-null object
Year                  1000 non-null int64
Runtime (Minutes)     1000 non-null int64
Rating                1000 non-null float64
Votes                 1000 non-null int64
Revenue (Millions)    872 non-null float64
Metascore             936 non-null float64
dtypes: float64(3), int64(4), object(4)
memory usage: 93.8+ KB

上面的输出信息中,包含了行和列的数量、非空值的数量、每个列中的数据类型以及DataFrame数据使用了多少内存。

可以看出,在RevenueMetascore列中有一些缺失值,后面章节将会讨论怎么处理这些缺失值。

快速查看数据类型很有用。例如,假设你刚刚导入了一些JSON,有些整数字段类型有可能被变为字符串,当计算时用到这些字段就会报“不支持的操作数”的错。调用.info()查看一下,就可以清楚看到整数列实际上都被变为了字符串。

shape

另一个有用的属性是.shape,表示DataFrame的形状(行、列)。

movies_df.shape

输出

(1000, 11)

注意,.shape是属性,不是函数(没有圆括号),它是一个元组(行、列)。可以看到,数据集movies DataFrame中有1000行和11列。

在清理和转换数据时,你可能会根据某些条件过滤一些行,然后想要知道删除了多少行,就可以使用.shape方法快速查看。

Python机器学习(八十六)Pandas 数据集信息

原文:https://www.cnblogs.com/huanghanyu/p/13174047.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!