Skip to content

Tag: pandas

what would be the most efficient way to do this in pandas

I’m trying to figure out the most efficient way to join two dataframes such as below. I’ve tried pd.merge and maybe using the rank function but cannot seem to figure a way. Thanks in advance df1 What I’m trying to achieve is this df2 Answer You might want to use groupby with unstack as advis…

Change structure of dictionary in Python Pandas

Is there a way of changing structure of nested dictionary? I have a column in dataframe with many rows of dictionaries, which looks like that: Is there a way of modifying structure, so that it will looks like without changing actual values? Answer You should read about the function apply() in pandas. You buil…

Iterating through a column and mapping values

Here is what I am trying to do. I want to substitute the values of this data frame. For example. Bernard to be substituted as 1, and then Drake as 2 and so on and so forth. How to iterate through the column to write a function that can do the following. Answer The function already exists – pd.factorize.…