David
David

Reputation: 51

Get first element from PySpark data frame

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      |
+-----------------+

Upvotes: 1

Views: 4095

Answers (2)

ZygD
ZygD

Reputation: 24386

Several alternatives:

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

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

Upvotes: 1

Soufian
Soufian

Reputation: 90

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

[5.0]

Upvotes: 0

Related Questions