Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 05:15 AM
I have a task to transform a dataframe.
The task is to collect all the columns in a row and embed it into a JSON string as a column.
Source DF:
Target DF:
Labels:
- Labels:
-
Columns
-
JSON
-
Json Format
-
Target
1 ACCEPTED SOLUTION
Accepted Solutions
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2022 12:14 AM
I was able to do this by converting df to rdd and then by applying map function to it.
rdd_1 = df.rdd.map(lambda row:
(row['ID'],
row.asDict()
)
)
rdd_2_df = rdd_1.toDF(['ID', 'Data'])
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2022 12:14 AM
I was able to do this by converting df to rdd and then by applying map function to it.
rdd_1 = df.rdd.map(lambda row:
(row['ID'],
row.asDict()
)
)
rdd_2_df = rdd_1.toDF(['ID', 'Data'])

