開始使用免費開始

使用 DataFrame 繪製計數圖

在這個練習中,我們要查看一份發給年輕人的問卷回覆。我們主要的問題是:有多少受訪的年輕人表示害怕蜘蛛?受試者被要求對「I am afraid of spiders」這句話表示同意或不同意。回覆介於 1 到 5,其中 1 代表「Strongly disagree」,5 代表「Strongly agree」。

為了幫你起步,問卷資料的 csv 檔案路徑已指派給變數 csv_filepath

請注意,因為 csv_filepath 是一個 Python 變數,所以在讀取 csv 時不需要在它外面加上引號。

本練習屬於課程

Seaborn 資料視覺化入門

檢視課程

練習說明

  • 使用標準命名匯入 Matplotlib、pandas 與 Seaborn。
  • 從位於 csv_filepath 的 csv 檔案建立名為 df 的 DataFrame。
  • 使用 countplot() 函式,搭配 x=data= 參數,建立一個以 "Spiders" 欄位值作為 x 軸的計數圖。
  • 顯示圖表。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import Matplotlib, pandas, and Seaborn




# Create a DataFrame from csv file


# Create a count plot with "Spiders" on the x-axis


# Display the plot
編輯並執行程式碼