The element that appears the most frequently in a series column is called the index (pands). The element that appears the most frequently in a series column is called the index ()

So record the way to get the key corresponding to the maximum value in the dictionary

Dict is used instead of dictionary names

Method 1

max(dict,key=dict.get)
min(dict,key=dict.get)
Copy the code

For those of you who are not familiar with Max () and min(), let me explain

Pass the get() method as an argument to the Max function, where the corresponding value of the element is compared. Note: the elements here are dict keys, because when a Max function is passed in as an iterable, dict keys are compared, so dict.keys() is passed in.

So it’s like comparing key 1, key 2… Key n, these are iterable objects, what are the criteria for comparing these objects?

Get (‘ key 1’), dict.get(‘ key 2’),… , dict. Get (key ‘n’), as compared (more accurate should be use the key (‘ 1 ‘key), the key (‘ 2’ key),… , key(‘ key n’)), which is bigger or smaller, which is Max

       

Method 2

min(dict, key=lambda k: dict[k])   
max(dict, key=lambda k: dict[k])   
Copy the code

I don’t need to explain this, it’s easy to understand