开始使用免费开始使用

巴黎的餐馆

在本课程的各个练习中,您将使用多个关于巴黎市的数据集。

本练习将从探索巴黎市中心餐馆的数据集开始(整理自 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()
编辑并运行代码