文件导入性能
您拿到了一大批需要导入到 Spark DataFrame 的数据。您想通过拆分文件来测试导入速度的差异。
现在有两类可用文件:departures_full.txt.gz 和 departures_xxx.txt.gz,其中 xxx 为 000 - 013。相同数量的行被平均分到每个文件中。
本练习是课程的一部分
使用 PySpark 进行数据清洗
练习说明
- 将
departures_full.txt.gz文件和所有departures_xxx.txt.gz文件分别导入到不同的 DataFrame 中。 - 对每个 DataFrame 运行一次计数,并比较各自的运行时间。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the full and split files into DataFrames
full_df = spark.read.csv('____')
split_df = ____(____)
# Print the count and run time for each DataFrame
start_time_a = time.time()
print("Total rows in full DataFrame:\t%d" % ____)
print("Time to run: %f" % (time.time() - start_time_a))
start_time_b = time.time()
print("Total rows in split DataFrame:\t%d" % ____)
print("Time to run: %f" % (time.time() - start_time_b))