开始使用免费开始使用

自定义 CSV 文件

有时需要以自定义方式将数据存储到 CSV 文件中。这可能包括使用不同的表头值、包含或排除 DataFrame 的索引列,或更改用于分隔列的字符。在本练习中,您将实践这些操作,并确保文件被保存到期望的文件路径。

pandas 库已按 pd 导入,且数据已经过转换,仅包含 "Quantity Ordered" 大于 1 的行。清洗后的 DataFrame 已存储在名为 clean_sales_data 的变量中。

本练习是课程的一部分

使用 Python 的 ETL 和 ELT

查看课程

练习说明

  • 导入 os 库。
  • 将清洗后的 DataFrame 写入存放在 path_to_write 的 CSV 文件中,且不包含表头。
  • 确认文件已写入到期望的路径。

交互式实操练习

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

# Import the os library
____

# Load the data to a csv file with the index, no header and pipe separated
def load(clean_data, path_to_write):
	clean_data.____(____, header=____, sep="|")

load(clean_sales_data, "clean_sales_data.csv")

# Check that the file is present.
file_exists = os.____.____(____)
print(file_exists)
编辑并运行代码