From a9a38a981628c08bca8527606f7c2defaa0d292d Mon Sep 17 00:00:00 2001 From: Scc_hy <34824890+scchy@users.noreply.github.com> Date: Tue, 31 Dec 2019 10:43:08 +0800 Subject: [PATCH] simplify departments_with_employees_seq departments_with_employees_seq = [eval('department_with_employees_{}'.format(i)) for i in range(1, 6)] --- code/chap07/dataframe_creation_from_rows.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/chap07/dataframe_creation_from_rows.py b/code/chap07/dataframe_creation_from_rows.py index 7f8913b..3095d9e 100644 --- a/code/chap07/dataframe_creation_from_rows.py +++ b/code/chap07/dataframe_creation_from_rows.py @@ -119,13 +119,15 @@ #========================================== # Create DataFrames from a list of the rows #========================================== + ## simplify + # departments_with_employees_seq = [eval('department_with_employees_{}'.format(i)) for i in range(1, 6)] departments_with_employees_seq_1 = [department_with_employees_1, department_with_employees_2, department_with_employees_5] df = spark.createDataFrame(departments_with_employees_seq_1) # df.show(truncate=False) df.printSchema() - + departments_with_employees_seq_2 = [department_with_employees_1, department_with_employees_3, department_with_employees_4, department_with_employees_5] df2 = spark.createDataFrame(departments_with_employees_seq_2)