搭配 Seaborn 使用 pandas

Seaborn 資料視覺化入門

Content Team

DataCamp

什麼是 pandas?

  • 用於資料分析的 Python 函式庫
  • 可輕鬆讀取 csv、txt 等檔案的資料集
  • 資料集以 DataFrame 物件呈現
Seaborn 資料視覺化入門

操作 DataFrame

import pandas as pd

df = pd.read_csv("masculinity.csv")
df.head()
    participant_id        age    how_masculine    how_important
0                1    18 - 34         Somewhat         Somewhat
1                2    18 - 34         Somewhat         Somewhat
2                3    18 - 34             Very         Not very
3                4    18 - 34             Very         Not very
4                5    18 - 34             Very             Very
Seaborn 資料視覺化入門

用 DataFrame 搭配 countplot()

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.read_csv("masculinity.csv")
sns.countplot(x="how_masculine", data=df)
plt.show()

「how_masculine」欄位的計數圖

Seaborn 資料視覺化入門

masculinity DataFrame 的前 10 列

Seaborn 資料視覺化入門

「不整潔」的 DataFrame

Seaborn 資料視覺化入門

一起來練習吧!

Seaborn 資料視覺化入門

Preparing Video For Download...