Python - 查詢 Pandas DataFrame 統計摘要
要查詢 DataFrame 的統計摘要,請使用 describe() 方法。首先,我們使用別名匯入了以下 pandas 庫
import pandas as pd
以下是我們的 CSV 檔案,我們正在建立一個 Pandas DataFrame −
dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")現在,獲取我們 Pandas DataFrame 的統計摘要 −
dataFrame.describe()
示例
以下為完整程式碼
import pandas as pd
# reading csv file
dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")
print("DataFrame...\n",dataFrame)
# count the rows and columns in a DataFrame
print("\nNumber of rows and column in our DataFrame = ",dataFrame.shape)
# summary of DataFrame
print("\nGet the summary of statistics of a DataFrame = \n",dataFrame.describe())
# returns top 7 row records
print("\nDataFrame with specific number of rows...\n",dataFrame.head(7))
輸出
這將產生以下輸出
DataFrame... Car Place UnitsSold 0 Audi Bangalore 80 1 Porsche Mumbai 110 2 RollsRoyce Pune 100 3 BMW Delhi 95 4 Mercedes Hyderabad 80 5 Lamborghini Chandigarh 80 6 Audi Mumbai 100 7 Mercedes Pune 120 8 Lamborghini Delhi 100 Number of rows and colums in our DataFrame = (9, 3) Get the summarry of statistics of a DataFrame = UnitsSold count 9.000000 mean 96.111111 std 14.092945 min 80.000000 25% 80.000000 50% 100.000000 75% 100.000000 max 120.000000 DataFrame with specific number of rows ... Car Place UnitsSold 0 Audi Bangalore 80 1 Porsche Mumbai 110 2 RollsRoyce Pune 100 3 BMW Delhi 95 4 Mercedes Hyderabad 80 5 Lamborghini Chandigarh 80 6 Audi Mumbai 100
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP