開始使用免費開始

巴黎的餐廳

在本課程的練習中,你會操作多個關於巴黎市的資料集。

這個練習先從探索市中心的餐廳資料集開始(彙整自 Paris Data 的開放資料)。資料包含餐廳地點的點座標,以及餐廳類型的描述。

我們預期你已熟悉 pandas 函式庫處理表格資料(Python 中的 DataFrame 物件)的基本功。在這裡,我們會用 pandas 讀取提供的 csv 檔,接著用 matplotlib 視覺化這些點。使用 matplotlib 時,先用 fig, ax = plt.subplots() 建立圖形與座標軸物件,然後使用這個座標軸物件 ax 來建立圖表。

本練習屬於課程

在 Python 中處理地理空間資料

檢視課程

練習說明

  • 將 pandas 以 pd 匯入,並將 matplotlib.pyplot 以 plt 匯入。
  • 讀取餐廳資料集("paris_restaurants.csv"),並指定給名為 restaurants 的變數。
  • 使用 head() 方法檢視 df 資料框的前 5 列。你有看到包含座標的欄嗎?
  • 使用 matplotlib 的 plot() 方法快速視覺化各區位置。

動手互動練習

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

# Import pandas and matplotlib
____
____

# Read the restaurants csv file
restaurants = ____

# Inspect the first rows of restaurants
print(____)

# Make a plot of all points
fig, ax = plt.subplots()
ax.plot(____, ____, 'o')
plt.show()
編輯並執行程式碼