0

I am trying to display just a few columns in Scala like just name, address and zip

I have this so far...

scala> pe06DS.filter(pe06data => pe06data.state == "OH").show()
+--------------+--------+----------+-----+-----+
|       address|    city|      name|state|  zip|
+--------------+--------+----------+-----+-----+
|84 Arcadia Dr.|Westlake|John Smith|   OH|44145|
+--------------+--------+----------+-----+-----+


scala> pe06DS.show()
+--------------------+--------+----------+-----+-----+
|             address|    city|      name|state|  zip|
+--------------------+--------+----------+-----+-----+
|      84 Arcadia Dr.|Westlake|John Smith|   OH|44145|
|8691 Rockledge St...|Westlake|  Jane Doe|   NY|12302|
|     6 Tallwood Road|Westlake|Tom Tucker|   OR|97402|
|     37 Chestnut Rd.|Westlake| Jack Hill|   MI|48150|
+--------------------+--------+----------+-----+-----+


scala> pe06DS.filter(pe06data => pe06data.state == "OH").show()
+--------------+--------+----------+-----+-----+
|       address|    city|      name|state|  zip|
+--------------+--------+----------+-----+-----+
|84 Arcadia Dr.|Westlake|John Smith|   OH|44145|
+--------------+--------+----------+-----+-----+

But can't just get to display only 3 columns with the filter

Lamanus
  • 12,898
  • 4
  • 21
  • 47
Lee Roger
  • 11
  • 1

1 Answers1

1

I got it. I just needed to think of the way around.

cala> pe06DS.filter(pe06data => pe06data.state == "OH").select(col("name").alias("Name"),col("address").alias("Address"),col("zip").alias("Zip")).show()
+----------+--------------+-----+
|      Name|       Address|  Zip|
+----------+--------------+-----+
|John Smith|84 Arcadia Dr.|44145|
+----------+--------------+-----+
ouflak
  • 2,458
  • 10
  • 44
  • 49
Lee Roger
  • 11
  • 1