Frederic Bastiat
Frederic Bastiat

Reputation: 693

casting multiple columns astype

Should be an easy to answer question... Am I doing this wrong? Can I not cast multiple columns?

>>> val results2 = results.select( results["HCAHPS Base Score"].cast(IntegerType).as(results["HCAHPS Base Score"]), results["HCAHPS Consistency Score"].cast(IntegerType).as(results["HCAHPS Consistency Score"]) )
File "<stdin>", line 1
val results2 = results.select( results["HCAHPS Base Score"].cast(IntegerType).as(results["HCAHPS Base Score"]), results["HCAHPS Consistency Score"].cast(IntegerType).as(results["HCAHPS Consistency Score"]) )
               ^
SyntaxError: invalid syntax

The syntax error keeps popping up right around the comma...

Upvotes: 0

Views: 1916

Answers (1)

Rags
Rags

Reputation: 1881

Try this. I assume this is pySpark as the question is tagged under PySpark

results2 = results.select( results["HCAHPS Base Score"].cast(IntegerType()).alias("HCAHPS Base Score"), results["HCAHPS Consistency Score"].cast(IntegerType()).alias("HCAHPS Consistency Score") )

In Scala, you may try the below.

val results2 = results.select( results["HCAHPS Base Score"].cast(IntegerType).as("HCAHPS Base Score"), results["HCAHPS Consistency Score"].cast(IntegerType).as("HCAHPS Consistency Score") )

Upvotes: 2

Related Questions