筛选
您也许还记得,在之前的练习中,最多的票务销售都发生在 Los Angeles,这让我们难以查看其他影院位置的表现。若要只查看数据的一个子集,比如某个影院位置,您需要对数据进行筛选。
本练习是课程的一部分
面向表格用户的 Python
练习说明
- 在 sales 的
theater_location列中筛选出New York——别忘了加引号! - 打印 New York 销售数据的前几行。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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.____())