Skip to content

Tag: dictionary

Create pandas series using a dictionary as mapper

Is there a built-in function to create a pandas.Series column using a dictionary as mapper and index levels in the data frame ? The idea is to create a new column based on values in index levels and a dictionary. For instance: Let’s suppose the following data frame, where id, name and code and different…

how to add just the values in key s1 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago. Improve this question List item Answer If you want to add all the values of s1, you need to iterate over the value…

How to implement a factory class?

I want to be able to create objects based on an enumeration class, and use a dictionary. Something like this: But I get the error: For some reason the dictionary can’t be created. Where am I going wrong here? Answer After looking at Bruce Eckel’s book I came up with this: This gets the user to sel…

convert dataframe row to dict

I have datarame like the sample data below. I’m trying to convert one row from the dataframe in to a dict like the desired output below. But when I use to_dict I get the indice along with the column value. Does anyone know how to get convert the row to a dict like the desired output? Any tips greatly ap…