Các cụm từ thường gặp

Nhập môn Spark SQL bằng Python

Mark Plutowski

Data Scientist

Huấn luyện

Nhập môn Spark SQL bằng Python

Dự đoán

Nhập môn Spark SQL bằng Python

Dự đoán từ cuối

Nhập môn Spark SQL bằng Python

Chuỗi

Nhập môn Spark SQL bằng Python

Chuỗi: phần cuối

Nhập môn Spark SQL bằng Python

Cáo nâu nhanh nhẹn

Nhập môn Spark SQL bằng Python

Ngoặc câu

Nhập môn Spark SQL bằng Python

Một kiểu tổng hợp khác

Nhập môn Spark SQL bằng Python

Video

Nhập môn Spark SQL bằng Python

Dữ liệu phân loại

Nhập môn Spark SQL bằng Python

Phân loại vs Thứ bậc

  • Phân loại: he, hi, she, that, they
  • Thứ bậc: 1, 2, 3, 4, 5
Nhập môn Spark SQL bằng Python

Phân tích chuỗi

Nhập môn Spark SQL bằng Python

Từ đứng trước và sau

Nhập môn Spark SQL bằng Python

Bộ 3 (3-tuple)

query3 = """
   SELECT 
   id,
   word AS w1,
   LEAD(word,1) OVER(PARTITION BY part ORDER BY id ) AS w2,
   LEAD(word,2) OVER(PARTITION BY part ORDER BY id ) AS w3
   FROM df
""" 
Nhập môn Spark SQL bằng Python

Hàm cửa sổ làm truy vấn con

query3agg = """
SELECT w1, w2, w3, COUNT(*) as count FROM (
   SELECT 
   word AS w1,
   LEAD(word,1) OVER(PARTITION BY part ORDER BY id ) AS w2,
   LEAD(word,2) OVER(PARTITION BY part ORDER BY id ) AS w3
   FROM df
)
GROUP BY w1, w2, w3 
ORDER BY count DESC
""" 

spark.sql(query3agg).show()
Nhập môn Spark SQL bằng Python

Hàm cửa sổ làm truy vấn con – đầu ra

+-----+-----+-----+-----+
|   w1|   w2|   w3|count|
+-----+-----+-----+-----+
|  one|   of|  the|   49|
|    i|think| that|   46|
|   it|   is|    a|   46|
|   it|  was|    a|   45|
| that|   it|  was|   38|
|  out|   of|  the|   35|
|.....|.....|.....|.....|
Nhập môn Spark SQL bằng Python

Bộ 3 xuất hiện nhiều nhất

+-----+-----+-----+-----+
|   w1|   w2|   w3|count|
+-----+-----+-----+-----+
|  one|   of|  the|   49|
|    i|think| that|   46|
|   it|   is|    a|   46|
|   it|  was|    a|   45|
| that|   it|  was|   38|
|  out|   of|  the|   35|
| that|    i| have|   35|
|there|  was|    a|   34|
|    i|   do|  not|   34|
| that|   it|   is|   33|
| that|   he|  was|   30|
| that|   he|  had|   30|
| that|    i|  was|   28|
+-----+-----+-----+-----+
Nhập môn Spark SQL bằng Python

Một kiểu tổng hợp khác

query3agg = """
SELECT w1, w2, w3, length(w1)+length(w2)+length(w3) as length FROM (
   SELECT 
   word AS w1,
   LEAD(word,1) OVER(PARTITION BY part ORDER BY id ) AS w2,
   LEAD(word,2) OVER(PARTITION BY part ORDER BY id ) AS w3
   FROM df
   WHERE part <> 0 and part <> 13
)
GROUP BY w1, w2, w3 
ORDER BY length DESC
""" 

spark.sql(query3agg).show(truncate=False)
Nhập môn Spark SQL bằng Python

Một kiểu tổng hợp khác

+-------------------+-------------------+---------------+------+
|                 w1|                 w2|             w3|length|
+-------------------+-------------------+---------------+------+
|comfortable-looking|           building|    two-storied|    38|
|         widespread|comfortable-looking|       building|    37|
|      extraordinary|      circumstances|      connected|    35|
|      simple-minded|      nonconformist|      clergyman|    35|
|       particularly|          malignant|  boot-slitting|    34|
|       unsystematic|        sensational|     literature|    33|
|       oppressively|        respectable|     frock-coat|    33|
|         relentless|        keen-witted|   ready-handed|    33|
|   travelling-cloak|                and|  close-fitting|    32|
|        ruddy-faced|      white-aproned|       landlord|    32|
|  fellow-countryman|            colonel|       lysander|    32|
+-------------------+-------------------+---------------+------+
Nhập môn Spark SQL bằng Python

Ayo berlatih!

Nhập môn Spark SQL bằng Python

Preparing Video For Download...