Skip to content
Advertisement

How to compare 2 dictionary values in Python and make pairs with common ones by keys?

I have 2 columns: one is the Pandas DateTime Dataframe (data["start"]) and the second is the tags, data["parallels"] for example. So i’m going to create a dictionary, like this:

JavaScript

So, the output dictionary is: {3: '1.0', 5: '1.0'} How can i check this dictionary if the values is equal (in the example both are) and after checking write down keys. The output keys i’m going to use as index by making equal column data["start")[5] == data["start][3]

I wonder how to do it automatically, if there are {2: '2.0', 3: '1.0', 4: '2.0', 5: '1.0'} dict for example.

Advertisement

Answer

Reverse the dictionary so that keys can be grouped together

JavaScript
JavaScript

Other than this, maybe you want to use pandas groupby and aggregate all indices

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