CSV を DataFrame に読み込む
前の演習では、RDD から DataFrame を作成する方法を見ました。一般的には、CSV ファイルからデータを読み込むのが DataFrame を作成する最も一般的な方法です。この演習では、すでに file_path として与えられている people.csv ファイルから PySpark の DataFrame を作成し、作成したオブジェクトが PySpark の DataFrame であることを確認します。
ワークスペースにはすでに SparkSession の spark と、people.csv へのパスである変数 file_path が用意されています。
この演習はコースの一部です
PySparkで学ぶBig Data入門
演習の手順
people.csvへのパスである変数file_pathから DataFrame を作成します。- 出力が PySpark の DataFrame であることを確認します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create an DataFrame from file_path
people_df = spark.____(file_path, header=True, inferSchema=True)
# Check the type of people_df
print("The type of people_df is", ____(people_df))