Python Pandas Dataframe.describe()使用及代碼實例
Python Pandas Dataframe.describe()
Python是進行數(shù)據(jù)分析的一種出色語言,主要是因為以數(shù)據(jù)為中心的Python軟件包具有奇妙的生態(tài)系統(tǒng)。
Pandas是其中的一種,使導(dǎo)入和分析數(shù)據(jù)更加容易。
Pandas describe()用于查看一些基本的統(tǒng)計詳細信息,例如數(shù)據(jù)幀的百分位數(shù),均值,標準差等或一系列數(shù)值。
當此方法應(yīng)用于一系列字符串時,它將返回不同的輸出,如以下示例所示。
DataFrame.describe(percentiles=None, include=None, exclude=None)
參數(shù)
percentile
:列出像0-1之間的數(shù)字的數(shù)據(jù)類型以返回各自的百分位數(shù)include
:描述 DataFrame 時要包括的數(shù)據(jù)類型列表。默認為無exclude
:描述 DataFrame 時要排除的數(shù)據(jù)類型列表。默認為無
返回類型
DataFrame 的統(tǒng)計摘要。
要下載以下示例中使用的數(shù)據(jù)集,請單擊此處。
在以下示例中,使用的 DataFrame 包含一些NBA球員的數(shù)據(jù)。
下面是任何操作之前的數(shù)據(jù)幀圖像。
范例1
描述具有對象和數(shù)字數(shù)據(jù)類型的 DataFrame
在此示例中,描述了 DataFrame ,并傳遞了['object']以包含參數(shù)以查看對象系列的描述。
將[.20,.40,.60,.80]傳遞給百分位數(shù)參數(shù),以查看數(shù)字系列的相應(yīng)百分位數(shù)。
# importing pandas module import pandas as pd # importing regex module import re # making data frame data = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv") # removing null values to avoid errors data.dropna(inplace = True) # percentile list perc =[.20, .40, .60, .80] # list of dtypes to include include =['object', 'float', 'int'] # calling describe method desc = data.describe(percentiles = perc, include = include) # display desc
輸出:
如輸出圖像中所示,返回了數(shù)據(jù)幀的統(tǒng)計描述以及各自傳遞的百分位數(shù)。
對于帶有字符串的列,返回NaN進行數(shù)字運算。
范例2
描述字符串系列
在此示例中,“名稱”列調(diào)用describe方法,以查看對象數(shù)據(jù)類型的行為。
# importing pandas module import pandas as pd # importing regex module import re # making data frame data = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv") # removing null values to avoid errors data.dropna(inplace = True) # calling describe method desc = data["Name"].describe() # display desc
輸出:
如輸出圖像中所示,describe()的行為對于一系列字符串是不同的。
在這種情況下,返回了不同的統(tǒng)計信息,例如值的計數(shù),唯一值,出現(xiàn)次數(shù)的最高值和發(fā)生頻率。
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python?Melt函數(shù)將寬格式的數(shù)據(jù)表轉(zhuǎn)換為長格式
在數(shù)據(jù)處理和清洗中,melt函數(shù)是Pandas庫中一個強大而靈活的工具,它的主要功能是將寬格式的數(shù)據(jù)表轉(zhuǎn)換為長格式,從而更方便進行分析和可視化,本文將深入探討melt函數(shù)的用法、參數(shù)解析以及實際應(yīng)用場景2023-12-12基于python實現(xiàn)計算兩組數(shù)據(jù)P值
這篇文章主要介紹了基于python實現(xiàn)計算兩組數(shù)據(jù)P值,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-07-07python實現(xiàn)將JPG、BMP圖片轉(zhuǎn)化為bgr
這篇文章主要介紹了python實現(xiàn)將JPG、BMP圖片轉(zhuǎn)化為bgr方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03