---
title: "dataframe-quick-inspection-helper (tc)"
description: 快速檢查 DataFrame：head()、tail()、info()、describe() 四個方法。
url: "https://aaronchan.com/zh/kb/dataframe-quick-inspection-helper/"
updated: "2026-09-15"
category: "Code-Python (tc)"
tags:
  - python
---

# dataframe-quick-inspection-helper (tc)

拿到一個 DataFrame，想快速知道它大概長怎樣，用這 4 個方法，一行就看得到。先準備一個 8 行的例子：

 Copy

```
import pandas as pd

df = pd.DataFrame({
    "name":   ["Alice", "Bob", "Carol", "Dave", "Eve", "Frank", "Grace", "Heidi"],
    "dept":   ["IT", "IT", "HR", "HR", "IT", "HR", "IT", "HR"],
    "salary": [5000, 6000, 5500, 5200, 7000, 5800, 6200, 5400],
})
```

## Example 1：head() — 看頭幾行

 Copy

```
df.head()
```

**output:**

```
    name dept  salary
0  Alice   IT    5000
1    Bob   IT    6000
2  Carol   HR    5500
3   Dave   HR    5200
4    Eve   IT    7000
```

---

## Example 2：tail() — 看尾幾行

 Copy

```
df.tail()
```

**output:**

```
    name dept  salary
3   Dave   HR    5200
4    Eve   IT    7000
5  Frank   HR    5800
6  Grace   IT    6200
7  Heidi   HR    5400
```

---

## Example 3：info() — 看欄位類型

 Copy

```
df.info()
```

**output:**

```
<class 'pandas.DataFrame'>
RangeIndex: 8 entries, 0 to 7
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype
---  ------  --------------  -----
 0   name    8 non-null      str
 1   dept    8 non-null      str
 2   salary  8 non-null      int64
dtypes: int64(1), str(2)
memory usage: 324.0 bytes
```

---

## Example 4：describe() — 看數字欄統計

 Copy

```
df.describe()
```

**output:**

```
            salary
count     8.000000
mean   5762.500000
std     641.287767
min    5000.000000
25%    5350.000000
50%    5650.000000
75%    6050.000000
max    7000.000000
```
