pandas.Series.describe#

Series.describe(percentiles=None, include=None, exclude=None, datetime_is_numeric=False)[源代码]#

生成描述性统计数据。

描述性统计包括总结数据集分布的中心趋势、分散度和形状的统计数据,不包括 NaN 价值。

分析数值序列和对象序列,以及 DataFrame 混合数据类型的列集。根据所提供的内容,输出会有所不同。有关更多详细信息,请参阅下面的说明。

参数
percentiles类似列表的数字,可选

要包含在输出中的百分比。所有值都应介于0和1之间。默认值为 [.25, .5, .75] ,它返回第25、50和75个百分位数。

include‘all’,类似列表的数据类型或无(默认),可选

要包括在结果中的数据类型白名单。忽略以下内容 Series 。以下是选项:

  • ‘All’:输入的所有列都将包含在输出中。

  • 类似列表的数据类型:将结果限制为所提供的数据类型。要将结果限制为数字类型,请提交 numpy.number 。若要将其限制为对象列,请提交 numpy.object 数据类型。字符串还可以在样式中使用 select_dtypes (例如 df.describe(include=['O']) )。要选择Pandas分类列,请使用 'category'

  • 无(默认):结果将包括所有数字列。

exclude类似列表的数据类型或无(默认)、可选、

要从结果中省略的数据类型黑名单。忽略以下内容 Series 。以下是选项:

  • 类似列表的数据类型:从结果中排除提供的数据类型。要排除数字类型,请提交 numpy.number 。要排除对象列,请提交数据类型 numpy.object 。字符串还可以在样式中使用 select_dtypes (例如 df.describe(exclude=['O']) )。若要排除Pandas分类列,请使用 'category'

  • 无(默认):结果将不排除任何内容。

datetime_is_numeric布尔值,默认为False

是否将DateTime数据类型视为数字。这会影响为该列计算的统计信息。对于DataFrame输入,它还控制默认情况下是否包括DateTime列。

1.1.0 新版功能.

退货
系列或DataFrame

提供的系列或数据帧的汇总统计信息。

参见

DataFrame.count

计算非NA/空观察值的数量。

DataFrame.max

对象中的最大值。

DataFrame.min

对象中的最小值。

DataFrame.mean

值的平均值。

DataFrame.std

观测数据的标准差。

DataFrame.select_dtypes

数据帧的子集,根据列的数据类型包括/排除列。

注意事项

对于数值数据,结果的索引将包括 countmeanstdminmax 以及更低的, 50 和较高的百分位数。默认情况下,较低的百分比为 25 上面的百分位数是 75 。这个 50 百分位数与中位数相同。

对于对象数据(例如字符串或时间戳),结果的索引将包括 countuniquetop ,以及 freq 。这个 top 是最常见的价值。这个 freq 是最常见的值的频率。时间戳还包括 firstlast 物品。

如果多个对象值具有最高计数,则 counttop 结果将从计票最高的人中任意选择。

类提供的混合数据类型 DataFrame ,则默认为仅返回对数值列的分析。如果数据帧仅由对象和类别数据组成,而不包含任何数字列,则默认情况下返回对象列和类别列的分析。如果 include='all' 作为选项提供,则结果将包括每种类型的属性的并集。

这个 includeexclude 参数可用于限制 DataFrame 对输出进行了分析。在分析 Series

示例

描述一个数字 Series

>>> s = pd.Series([1, 2, 3])
>>> s.describe()
count    3.0
mean     2.0
std      1.0
min      1.0
25%      1.5
50%      2.0
75%      2.5
max      3.0
dtype: float64

描述一个绝对的 Series

>>> s = pd.Series(['a', 'a', 'b', 'c'])
>>> s.describe()
count     4
unique    3
top       a
freq      2
dtype: object

描述时间戳 Series

>>> s = pd.Series([
...   np.datetime64("2000-01-01"),
...   np.datetime64("2010-01-01"),
...   np.datetime64("2010-01-01")
... ])
>>> s.describe(datetime_is_numeric=True)
count                      3
mean     2006-09-01 08:00:00
min      2000-01-01 00:00:00
25%      2004-12-31 12:00:00
50%      2010-01-01 00:00:00
75%      2010-01-01 00:00:00
max      2010-01-01 00:00:00
dtype: object

描述一种 DataFrame 。默认情况下,仅返回数值字段。

>>> df = pd.DataFrame({'categorical': pd.Categorical(['d','e','f']),
...                    'numeric': [1, 2, 3],
...                    'object': ['a', 'b', 'c']
...                   })
>>> df.describe()
       numeric
count      3.0
mean       2.0
std        1.0
min        1.0
25%        1.5
50%        2.0
75%        2.5
max        3.0

描述的所有列 DataFrame 而不考虑数据类型。

>>> df.describe(include='all')  
       categorical  numeric object
count            3      3.0      3
unique           3      NaN      3
top              f      NaN      a
freq             1      NaN      1
mean           NaN      2.0    NaN
std            NaN      1.0    NaN
min            NaN      1.0    NaN
25%            NaN      1.5    NaN
50%            NaN      2.0    NaN
75%            NaN      2.5    NaN
max            NaN      3.0    NaN

描述来自 DataFrame 通过将其作为属性进行访问。

>>> df.numeric.describe()
count    3.0
mean     2.0
std      1.0
min      1.0
25%      1.5
50%      2.0
75%      2.5
max      3.0
Name: numeric, dtype: float64

中仅包含数字列。 DataFrame 描述。

>>> df.describe(include=[np.number])
       numeric
count      3.0
mean       2.0
std        1.0
min        1.0
25%        1.5
50%        2.0
75%        2.5
max        3.0

中仅包含字符串列。 DataFrame 描述。

>>> df.describe(include=[object])  
       object
count       3
unique      3
top         a
freq        1

仅包括来自 DataFrame 描述。

>>> df.describe(include=['category'])
       categorical
count            3
unique           3
top              d
freq             1

对象中排除数字列 DataFrame 描述。

>>> df.describe(exclude=[np.number])  
       categorical object
count            3      3
unique           3      3
top              f      a
freq             1      1

从中排除对象列 DataFrame 描述。

>>> df.describe(exclude=[object])  
       categorical  numeric
count            3      3.0
unique           3      NaN
top              f      NaN
freq             1      NaN
mean           NaN      2.0
std            NaN      1.0
min            NaN      1.0
25%            NaN      1.5
50%            NaN      2.0
75%            NaN      2.5
max            NaN      3.0