Home > Blockchain >  Get first element from PySpark data frame
Get first element from PySpark data frame

Time:07-14

I have a PySpark data frame which only contains one element. How can I extract the number from the data frame?

For the example, how can I get the number 5.0 from the PySpark data frame?

 ----------------- 
|        count    |
 ----------------- 
|        5.0      |
 ----------------- 

CodePudding user response:

sc.parallelize([5.0]).collect()

[5.0]

CodePudding user response:

Several alternatives:

df.head()[0]
df.head().count
df.head()['count']

first does the same, but head is 1 letter shorter ;)

  • Related