开始使用免费开始使用

端到端测试数据管道

在本练习中,您将继续使用先前相同的数据管道,它会抽取、转换并加载税务数据。您将练习对该管道进行端到端测试,确保该解决方案可以多次运行,且不会在 parquet 文件中重复写入转换后的数据。

pandas 已以 pd 名称导入,extract()transform()load() 函数也已定义。

本练习是课程的一部分

使用 Python 的 ETL 和 ELT

查看课程

练习说明

  • 使用 for 循环将 ETL 管道运行 3 次。
  • 在管道每次运行的迭代中,打印 clean_tax_data 的形状。
  • 将存储在 "clean_tax_data.parquet" 文件中的 DataFrame 读入变量 to_validate
  • 输出 to_validate DataFrame 的形状,并与 clean_tax_rate 的形状进行比较,以确保每次运行管道时数据没有被重复。

交互式实操练习

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

# Trigger the data pipeline to run three times
____ attempt in range(0, ____):
	print(f"Attempt: {attempt}")
	raw_tax_data = extract("raw_tax_data.csv")
	clean_tax_data = transform(raw_tax_data)
	load(clean_tax_data, "clean_tax_data.parquet")
	
	# Print the shape of the cleaned_tax_data DataFrame
	print(f"Shape of clean_tax_data: {clean_tax_data.____}")
    
# Read in the loaded data, check the shape
to_validate = pd.____("clean_tax_data.parquet")
print(f"Final shape of cleaned data: {to_validate.____}")
编辑并运行代码