Skip to content
Advertisement

Add values to new column from a dict with keys matching the index of a dataframe

I have a dictionary that for examples sake, looks like

JavaScript

I have a dataframe that has the same index values as the keys in this dict.

I want to add each value from the dict to the dataframe.

I feel like doing a check for every row of the DF, checking the index value, matching it to the one in the dict, then trying to add it is going to be a very slow way right?

Advertisement

Answer

You can use map and assign back to a new column:

JavaScript

prints:

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