ฟังก์ชัน describe() ให้สถิติพื้นฐานของ DataFrame ทั้ง Numeric และ Object Columns ได้ในครั้งเดียว ช่วย EDA (Exploratory Data Analysis) ให้รวดเร็ว
ตัวอย่างโค้ด
import pandas as pd
my_data = {
'Name': pd.Series(['Tom', 'Jane', 'Vin', 'Eve', 'Will']),
'Age': pd.Series([45, 67, 89, 12, 23]),
'value': pd.Series([8.79, 23.24, 31.98, 78.56, 90.20])
}
my_df = pd.DataFrame(my_data)
print("The dataframe is:")
print(my_df)
print("\nThe description of data is:")
print(my_df.describe())
ผลลัพธ์
The dataframe is:
Name Age value
0 Tom 45 8.79
1 Jane 67 23.24
2 Vin 89 31.98
3 Eve 12 78.56
4 Will 23 90.20
The description of data is:
Age value
count 5.000000 5.000000
mean 47.200000 46.554000
std 31.499206 35.747102
min 12.000000 8.790000
25% 23.000000 23.240000
50% 45.000000 31.980000
75% 67.000000 78.560000
max 89.000000 90.200000
คำอธิบายสถิติแต่ละตัว
| สถิติ | คำอธิบาย |
|---|---|
| count | จำนวนค่า Non-null |
| mean | ค่าเฉลี่ยเลขคณิต |
| std | ส่วนเบี่ยงเบนมาตรฐาน (Sample Std, ddof=1) |
| min | ค่าต่ำสุด |
| 25% | Percentile 25 (Q1) |
| 50% | Median (Q2) |
| 75% | Percentile 75 (Q3) |
| max | ค่าสูงสุด |