开始使用免费开始使用

使用 pandas 加载数据

在训练机器学习模型之前,您需要先导入数据。实现方式有多种,这里我们先使用 pandas 的一行代码:pd.read_csv()。请回忆视频中提到,首个参数用于指定路径或 URL,其他参数均为可选。

在本练习中,您将导入 King County 的房价数据集。我们会在本章稍后用它来训练一个线性模型。

本练习是课程的一部分

Python 中的 TensorFlow 入门

查看课程

练习说明

  • pandas 以别名 pd 导入。
  • 将路径赋给名为 data_path 的字符串变量。
  • 将数据集加载为名为 housing 的 pandas 数据框。
  • 打印 housingprice 列。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import pandas under the alias pd
____

# Assign the path to a string variable named data_path
____ = 'kc_house_data.csv'

# Load the dataset as a dataframe named housing
____ = pd.read_csv(____)

# Print the price column of housing
print(____)
编辑并运行代码