Skip to content
Advertisement

Add new columns to dataframe from dictionary for every row

I want to add columns in a dataframe from a dictionary where keys are randomly generated and for every row of the dataframe the values of keys should be added

JavaScript

and the dataframe is like following:

JavaScript

How can I do it ?

expecetd outcome:

JavaScript

Advertisement

Answer

You can craft a DataFrame from the dictionary and use a cross merge:

JavaScript

output:

JavaScript

renaming original columns if existing in the dictionary:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement