Spark - extracting single value from DataFrame

前端 未结 3 1935
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 20:55

I have a Spark DataFrame query that is guaranteed to return single column with single Int value. What is the best way to extract this value as Int from the resulting DataFrame?<

3条回答
  •  名媛妹妹
    2021-01-30 21:11

    In Pyspark, you can simply get the first element if the dataframe is single entity with one column as a response, otherwise, a whole row will be returned, then you have to get dimension-wise response i.e. 2 Dimension list like df.head()[0][0]

    df.head()[0]
    

提交回复
热议问题