Spark DataFrame equivalent to Pandas Dataframe `.iloc()` method?

后端 未结 3 447
广开言路
广开言路 2020-12-19 02:12

Is there a way to reference Spark DataFrame columns by position using an integer?

Analogous Pandas DataFrame operation:

df.iloc[:0] # Give me all the         


        
3条回答
  •  长情又很酷
    2020-12-19 02:18

    The equivalent of Python df.iloc is collect

    PySpark examples:

    X = df.collect()[0]['age'] 
    

    or

    X = df.collect()[0][1]  #row 0 col 1
    

提交回复
热议问题