PySparkで学ぶBig Data入門
Upendra Devisetty
Science Analyst, CyVerse
データ可視化はデータをグラフやチャートで表す方法です
Python のオープンソース可視化ツール:
PySpark の DataFrame を描画する主な方法は3つ
pyspark_dist_explore ライブラリ
toPandas()
HandySpark ライブラリ
Pyspark_dist_explore は DataFrame の素早い可視化に有用です
利用可能な関数は3つ: hist()、distplot()、pandas_histogram()
test_df = spark.read.csv("test.csv", header=True, inferSchema=True)
test_df_age = test_df.select('Age')
hist(test_df_age, bins=20, color="red")
test_df = spark.read.csv("test.csv", header=True, inferSchema=True)
test_df_sample_pandas = test_df.toPandas()
test_df_sample_pandas.hist('Age')
toPandas() は非推奨ですpandas の DataFrame は単一サーバーのメモリ上、PySpark の処理は並列実行
pandas は操作ごとに即時評価、PySpark の DataFrame は遅延評価
pandas の DataFrame は可変、PySpark の DataFrame は不変
pandas API は PySpark DataFrame API より操作が豊富
test_df = spark.read.csv('test.csv', header=True, inferSchema=True)
hdf = test_df.toHandy()
hdf.cols["Age"].hist()
PySparkで学ぶBig Data入門