Pandas Describe函數(shù)的具體使用
前言
在 Pandas 中,describe()
函數(shù)能夠?yàn)閿?shù)據(jù)框(DataFrame)中的數(shù)值列提供統(tǒng)計(jì)摘要信息。
一、describe() 函數(shù)是什么?
describe()
函數(shù)是 Pandas 數(shù)據(jù)框(DataFrame)對(duì)象的一個(gè)方法,它用于生成有關(guān)數(shù)據(jù)的統(tǒng)計(jì)摘要。這個(gè)統(tǒng)計(jì)摘要包括了數(shù)據(jù)列的數(shù)量、均值、標(biāo)準(zhǔn)差、最小值、25% 分位數(shù)、中位數(shù)(50% 分位數(shù))、75% 分位數(shù)和最大值。
二、describe()函數(shù)的基本用法
import pandas as pd # 創(chuàng)建一個(gè)示例數(shù)據(jù)框 data = {'Age': [25, 30, 35, 40, 45], 'Salary': [50000, 60000, 75000, 80000, 90000]} df = pd.DataFrame(data) # 使用 describe() 函數(shù)生成統(tǒng)計(jì)摘要 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ù)說(shuō)明
describe()
函數(shù)有一些可選參數(shù),可以用來(lái)控制統(tǒng)計(jì)摘要的輸出。
percentiles
:指定要計(jì)算的百分位數(shù),默認(rèn)是[0.25, 0.5, 0.75]
,即 25%、50% 和 75% 分位數(shù)。include
和exclude
:用于選擇要包含或排除的數(shù)據(jù)類型,默認(rèn)情況下包括所有數(shù)值列。datetime_is_numeric
:如果為 True,則將日期時(shí)間列視為數(shù)值列進(jìn)行統(tǒng)計(jì)。
四、示例代碼
1. 使用 percentiles參數(shù)
設(shè)置 percentiles
參數(shù)來(lái)自定義要計(jì)算的百分位數(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ù)來(lái)選擇要包含或排除的數(shù)據(jù)類型。
integer_summary = df.describe(include='int') print(integer_summary)
3. 處理日期時(shí)間列
如果數(shù)據(jù)框中包含日期時(shí)間列,使用 datetime_is_numeric
參數(shù)將其視為數(shù)值列進(jìn)行統(tǒng)計(jì)。例如:
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)
到此這篇關(guān)于Pandas Describe函數(shù)的具體使用的文章就介紹到這了,更多相關(guān)Pandas describe()內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python+Matplotlib實(shí)現(xiàn)給圖像添加文本標(biāo)簽與注釋
這篇文章主要為大家分享一下如何使用python+matplotlib給繪制的圖像添加文本標(biāo)簽與注釋。文中的示例代碼講解詳細(xì),感興趣的可以了解一下2022-04-04通過(guò)Python實(shí)現(xiàn)自動(dòng)填寫調(diào)查問(wèn)卷
這篇文章主要介紹了通過(guò)Python實(shí)現(xiàn)自動(dòng)填寫調(diào)查問(wèn)卷的相關(guān)資料,需要的朋友可以參考下2017-09-09Python如何解決secure_filename對(duì)中文不支持問(wèn)題
最近使用到了secure_filename,然后悲劇的發(fā)現(xiàn)中文居然不展示出來(lái),本文就詳細(xì)的介紹一下解決方法,感興趣的可以了解一下2021-07-07python實(shí)現(xiàn)Scrapy爬取網(wǎng)易新聞
這篇文章主要介紹了python實(shí)現(xiàn)Scrapy爬取網(wǎng)易新聞,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03一文帶你了解Python中的數(shù)據(jù)序列化與反序列化
Python提供了豐富的工具和庫(kù)來(lái)處理數(shù)據(jù)序列化與反序列化,本文帶領(lǐng)大家一起學(xué)習(xí),包括基本概念、常見(jiàn)的序列化格式、示例和最佳實(shí)踐,快跟隨小編一起學(xué)習(xí)起來(lái)吧2023-10-10python實(shí)現(xiàn)微信發(fā)送郵件關(guān)閉電腦功能
這篇文章主要介紹了python實(shí)現(xiàn)微信發(fā)送郵件關(guān)閉電腦功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02