欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Pandas Describe函數(shù)的具體使用

 更新時間:2024年02月04日 15:36:40   作者:武帝為此  
在Pandas中,describe()能夠為數(shù)據(jù)框中的數(shù)值列提供統(tǒng)計摘要信息,本文主要介紹了Pandas Describe函數(shù)的具體使用,具有一定的參考價值,感興趣的可以了解一下

前言

在 Pandas 中,describe() 函數(shù)能夠為數(shù)據(jù)框(DataFrame)中的數(shù)值列提供統(tǒng)計摘要信息。

一、describe() 函數(shù)是什么?

describe() 函數(shù)是 Pandas 數(shù)據(jù)框(DataFrame)對象的一個方法,它用于生成有關數(shù)據(jù)的統(tǒng)計摘要。這個統(tǒng)計摘要包括了數(shù)據(jù)列的數(shù)量、均值、標準差、最小值、25% 分位數(shù)、中位數(shù)(50% 分位數(shù))、75% 分位數(shù)和最大值。

二、describe()函數(shù)的基本用法

import pandas as pd

# 創(chuàng)建一個示例數(shù)據(jù)框
data = {'Age': [25, 30, 35, 40, 45],
        'Salary': [50000, 60000, 75000, 80000, 90000]}

df = pd.DataFrame(data)

# 使用 describe() 函數(shù)生成統(tǒng)計摘要
summary = df.describe()

print(summary)

             Age        Salary
count   5.000000      5.000000
mean   35.000000  71000.000000
std     7.905694  15968.719423
min    25.000000  50000.000000
25%    30.000000  60000.000000
50%    35.000000  75000.000000
75%    40.000000  80000.000000
max    45.000000  90000.000000

三、describe() 函數(shù)的參數(shù)說明

describe() 函數(shù)有一些可選參數(shù),可以用來控制統(tǒng)計摘要的輸出。

  • percentiles:指定要計算的百分位數(shù),默認是 [0.25, 0.5, 0.75],即 25%、50% 和 75% 分位數(shù)。
  • include 和 exclude:用于選擇要包含或排除的數(shù)據(jù)類型,默認情況下包括所有數(shù)值列。
  • datetime_is_numeric:如果為 True,則將日期時間列視為數(shù)值列進行統(tǒng)計。

四、示例代碼

1. 使用 percentiles參數(shù)

設置 percentiles 參數(shù)來自定義要計算的百分位數(shù)。例如:

custom_percentiles = [0.1, 0.5, 0.9]
custom_summary = df.describe(percentiles=custom_percentiles)
print(custom_summary)

2. 使用 include 和 exclude 參數(shù)

使用 include 和 exclude 參數(shù)來選擇要包含或排除的數(shù)據(jù)類型。

integer_summary = df.describe(include='int')
print(integer_summary)

3. 處理日期時間列

如果數(shù)據(jù)框中包含日期時間列,使用 datetime_is_numeric 參數(shù)將其視為數(shù)值列進行統(tǒng)計。例如:

import datetime

dates = [datetime.date(2022, 1, 1), datetime.date(2022, 1, 2), datetime.date(2022, 1, 3)]
df['Date'] = dates

date_summary = df.describe(datetime_is_numeric=True)
print(date_summary)

到此這篇關于Pandas Describe函數(shù)的具體使用的文章就介紹到這了,更多相關Pandas describe()內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家! 

相關文章

最新評論