Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access a specific item in PySpark dataframe

How can I access value at a certain index of a column in PySpark dataframe for example I want to access value at index 5 of a column named "Category". How can I do that in PySpark syntax?

like image 206
moirK Avatar asked Mar 07 '18 09:03

moirK


1 Answers

Something like this,

value = df.where(df.index == 5).select('Category').collect()[0]['Category']
                                         #assuming 'index' is index column
like image 56
mayank agrawal Avatar answered Sep 27 '22 22:09

mayank agrawal