開始使用免費開始

篩選

你或許還記得在先前的練習中,最多的票房都發生在 Los Angeles,讓我們不容易觀察其他戲院地點的表現。若你想查看資料的一個子集,例如特定的一個戲院地點,就需要先把資料篩選出來。

本練習屬於課程

給試算表使用者的 Python

檢視課程

練習說明

  • 僅篩選 sales 的 theater_location 欄位為 New York 的資料——別忘了加上引號!
  • 列印 New York 銷售資料的開頭(head)。

動手互動練習

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

# Import the pandas package as pd
import pandas as pd

# Read in the Excel file
sales = pd.read_excel('ticket_sales.xlsx')

# Filter for New York sales only
new_york_sales = sales[sales[____] == ____].reset_index(drop=True)

# Print the first 5 rows of new_york_sales
____(new_york_sales.____())
編輯並執行程式碼