Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in Big Data Hadoop & Spark by (1k points)

I want to select a column that equals to a certain value. I am doing this in scala and having a little trouble.

Heres my code

df.select(df("state")==="TX").show()

this returns the state column with boolean values instead of just TX

Ive also tried

df.select(df("state")=="TX").show() 

but this doesn't work either.

closed

2 Answers

+1 vote
by (13.2k points)
selected by
 
Best answer

You can use dataframe.filter(condition)

For your code, the condition will be df(“state”) === “TX” ,

             df.filter(df("state")==="TX").show()

0 votes
by (32.3k points)
edited by

I solved the same problem using the syntax below:

df.filter(df("state")==="TX").show()

If you want to know more about Scala, then do check out this awesome video tutorial:

Browse Categories

...