使用 PySpark 的 Big Data 基礎
Upendra Devisetty
Science Analyst, CyVerse
資料視覺化是用圖表呈現資料的方法
Python 常用的開源繪圖工具:
用 PySpark DataFrame 繪圖可用三種方式
pyspark_dist_explore 函式庫
toPandas()
HandySpark 函式庫
Pyspark_dist_explore 函式庫可快速從 DataFrame 取得洞見
目前提供三個函式: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 基礎