开始使用免费开始使用

将销售数据加载到 CSV 文件

加载数据是任何数据管道中的关键环节。它确保下游的数据使用方和流程可以可靠访问您在管道前面阶段提取并转换的数据。在本练习中,您将练习使用 pandas(已导入为 pd)将转换后的销售数据加载到 CSV 文件中。此外,原始数据已完成提取,并存放在 DataFrame raw_sales_data 中。

本练习是课程的一部分

使用 Python 的 ETL 和 ELT

查看课程

练习说明

  • 筛选 raw_sales_data DataFrame,仅保留价格低于 25 美元的所有商品。
  • 更新 load() 函数,将转换后的销售数据写入名为 "transformed_sales_data.csv" 的文件中,并确保不包含 index 列。
  • 对清洗后的 DataFrame 调用 load() 函数。

交互式实操练习

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

def transform(raw_data):
	# Find the items prices less than 25 dollars
	return raw_data.loc[raw_data["Price Each"] ____ ____, ["Order ID", "Product", "Price Each", "Order Date"]]

def load(clean_data):
	# Write the data to a CSV file without the index column
	____.____("transformed_sales_data.csv", index=____)


clean_sales_data = transform(raw_sales_data)

# Call the load function on the cleaned DataFrame
____(____)
编辑并运行代码