PySpark dataframe show all Rows
DataFrames play a vital role in PySpark for performing data manipulation and analysis. Displaying DataFrames in a clear and readable format is essential for understanding and debugging data transformations. In this guide, we'll walk through how to display a DataFrame in PySpark.
Movie Name | Review |
---|---|
Kalki 2898 AD | "Kalki 2898 AD" is a cinematic marvel that seamlessly blends mythology with modern storytelling, and Prabhas delivers a performance that is both powerful and captivating. |
Robot | This is one of the best movies I've ever watched. After 2000, all of Shankar's movies have been either a blockbuster or a super hit. |
from pyspark.sql import SparkSession from pyspark import Row from pyspark.sql.types import StructType,StructField,StringType
spark_session=SparkSession.builder.master("local").appName("print rows ").getOrCreate() data = [ Row("Kalki 2898 AD","\"Kalki\" is a cinematic marvel that seamlessly blends mythology with modern storytelling, and Prabhas delivers a performance that is both powerful and captivating"), Row( "Robot","This is one of the best movies I've ever watched. After 2000 all of Shankar's movies have been either a blockbuster or super hit."), ] schema=StructType( [StructField("movie",StringType(),True),StructField("review",StringType(),True)]) df=spark_session.createDataFrame(data,schema)
By default show function prints 20 rows
df.show()
Below statement will print 10 rows
df.show(10)
if you use false option then it will not truncate column value its too long
df.show(2,false)
from pyspark.sql import SparkSession from pyspark import Row from pyspark.sql.types import StructType,StructField,StringType spark_session=SparkSession.builder.master("local").appName("print rows ").getOrCreate() data = [ Row("Kalki 2898 AD","\"Kalki\" is a cinematic marvel that seamlessly blends mythology with modern storytelling, and Prabhas delivers a performance that is both powerful and captivating"), Row( "Robot","This is one of the best movies I've ever watched. After 2000 all of Shankar's movies have been either a blockbuster or super hit."), ] schema=StructType( [StructField("movie",StringType(),True),StructField("review",StringType(),True)]) df=spark_session.createDataFrame(data,schema) df.show(2,False)