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ù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Python+Matplotlib實現(xiàn)給圖像添加文本標簽與注釋
這篇文章主要為大家分享一下如何使用python+matplotlib給繪制的圖像添加文本標簽與注釋。文中的示例代碼講解詳細,感興趣的可以了解一下2022-04-04通過Python實現(xiàn)自動填寫調(diào)查問卷
這篇文章主要介紹了通過Python實現(xiàn)自動填寫調(diào)查問卷的相關資料,需要的朋友可以參考下2017-09-09Python如何解決secure_filename對中文不支持問題
最近使用到了secure_filename,然后悲劇的發(fā)現(xiàn)中文居然不展示出來,本文就詳細的介紹一下解決方法,感興趣的可以了解一下2021-07-07python實現(xiàn)Scrapy爬取網(wǎng)易新聞
這篇文章主要介紹了python實現(xiàn)Scrapy爬取網(wǎng)易新聞,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-03-03一文帶你了解Python中的數(shù)據(jù)序列化與反序列化
Python提供了豐富的工具和庫來處理數(shù)據(jù)序列化與反序列化,本文帶領大家一起學習,包括基本概念、常見的序列化格式、示例和最佳實踐,快跟隨小編一起學習起來吧2023-10-10python實現(xiàn)微信發(fā)送郵件關閉電腦功能
這篇文章主要介紹了python實現(xiàn)微信發(fā)送郵件關閉電腦功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-02-02