使用 PySpark 的大数据基础
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 的大数据基础