第 1 部分:从 CSV 文件创建 DataFrame
每隔 4 年,世界各地的足球迷都会迎来一场名为"Fifa World Cup"的盛会,许多国家的方方面面也随之改变。在这道分为 3 部分的练习中,您将使用 PySpark SQL 对 "FIFA 2018 World Cup Player" 数据集做一些探索性数据分析(EDA),内容包括 DataFrame 操作、SQL 查询和可视化。
在第一部分,您将把 CSV 格式的 FIFA 2018 World Cup Players 数据集(Fifa2018_dataset.csv)加载为 PySpark 的 DataFrame,并使用基础的 DataFrame 操作来查看数据。
请记住,您的工作区中已经提供了 SparkSession spark 和变量 file_path。
本练习是课程的一部分
使用 PySpark 的大数据基础
练习说明
- 从
file_path(指向Fifa2018_dataset.csv文件的路径)创建一个 PySpark DataFrame。 - 打印该 DataFrame 的 schema。
- 打印前 10 条观测。
- 该 DataFrame 一共有多少行?
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Load the Dataframe
fifa_df = spark.____(____, header=True, inferSchema=True)
# Check the schema of columns
fifa_df.____()
# Show the first 10 observations
fifa_df.____(____)
# Print the total number of rows
print("There are {} rows in the fifa_df DataFrame".format(fifa_df.____()))