close

How to print only a certain column of DataFrame in PySpark?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to print only a certain column of DataFrame in PySpark in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to print only a certain column of DataFrame in PySpark?

  1. How to print only a certain column of DataFrame in PySpark?

    Bracket notation (df[df.col]) is used only for logical slicing and columns by itself (df.col) are not distributed data structures but SQL expressions and cannot be collected.

  2. print only a certain column of DataFrame in PySpark

    Bracket notation (df[df.col]) is used only for logical slicing and columns by itself (df.col) are not distributed data structures but SQL expressions and cannot be collected.

Method 1

select and show:

df.select("col").show()

or selectflatMapcollect:

df.select("col").rdd.flatMap(list).collect()

Bracket notation (df[df.col]) is used only for logical slicing and columns by itself (df.col) are not distributed data structures but SQL expressions and cannot be collected.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read