Big Data Fundamentals with PySpark
Upendra Devisetty
Science Analyst, CyVerse
การแสดงผลข้อมูล คือการนำเสนอข้อมูลในรูปแบบกราฟหรือแผนภูมิ
เครื่องมือพล็อตกราฟ open source สำหรับ Python:
การพล็อตกราฟจาก PySpark DataFrames ทำได้ 3 วิธี
ไลบรารี pyspark_dist_explore
toPandas()
ไลบรารี HandySpark
ไลบรารี Pyspark_dist_explore ช่วยให้เห็นภาพรวมของ DataFrames ได้อย่างรวดเร็ว
ฟังก์ชันที่มีให้ใช้งาน 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 DataFrames เก็บข้อมูลในหน่วยความจำบนเซิร์ฟเวอร์เดียว ส่วน PySpark ประมวลผลแบบขนาน
Pandas แสดงผลทันทีเมื่อมีการดำเนินการ ขณะที่ PySpark DataFrame ใช้ lazy evaluation
Pandas DataFrame เป็น mutable ส่วน PySpark DataFrames เป็น immutable
Pandas API รองรับการดำเนินการมากกว่า PySpark DataFrame API
test_df = spark.read.csv('test.csv', header=True, inferSchema=True)
hdf = test_df.toHandy()
hdf.cols["Age"].hist()
Big Data Fundamentals with PySpark