+1 vote
1 view
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.

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 (31.4k 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:

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...