Saturday, July 25, 2026
HomeLanguagesBuilding a row from a dictionary in PySpark

Building a row from a dictionary in PySpark

In this article, we will discuss how to build a row from the dictionary in PySpark

For doing this, we will pass the dictionary to the Row() method.

Syntax:

Syntax: Row(dict)

Example 1: Build a row with key-value pair (Dictionary) as arguments.

Here, we are going to pass the Row with Dictionary 

Syntax: Row({‘Key’:”value”, ‘Key’:”value”,’Key’:”value”})

Python3




# import Row
from pyspark.sql import Row
  
# dict
dic = {'First_name':"Sravan"
       'Last_name':"Kumar",
       'address':"hyderabad"}
  
# create a row with three values
# as dictionary.
row = Row(dic)
  
# display row
print(row)


Output:

<Row({‘First_name’: ‘Sravan’, ‘Last_name’: ‘Kumar’, ‘address’: ‘hyderabad’})>

Example 2: Python program to build two Rows with dictionary.

Syntax: Row(dict, dict)

Code:

Python3




# import Row
from pyspark.sql import Row
  
dic_1 = {'First_name':"Sravan"
         'Last_name':"Kumar",
         'address':"hyderabad"}
  
dic_2 = {'First_name':"Bobby",
         'Last_name':"Gottumukkala",
         'address':"Ponnur"}
  
# create two rows with
# three values as dictionary.
row = [Row(dic_1),
       Row(dic_2)]
# display row
print(row)


Output:

[<Row({‘First_name’: ‘Sravan’, ‘Last_name’: ‘Kumar’, ‘address’: ‘hyderabad’})>,

 <Row({‘First_name’: ‘Bobby’, ‘Last_name’: ‘Gottumukkala’, ‘address’: ‘Ponnur’})>]

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

5 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS