id |car_id
0 | 32
. | 2
. | 3
. | 7
. | 3
. | 4
. | 32
N | 1
How do you choose the most and the least frequent numbers from the id_car column and present them in a new table with as it often appears?'car_id' and 'quantity'
mdata['car_id'].value_counts().idxmax()
Here's some code that will provide the most frequent ID and the three least-frequent IDs.
count_pairs
has a list of pairs of (ID, count for that ID). It is sorted from most frequent to least frequent.most_common
doesn't tell us the order of ties.You may change the n to 1 if you only want any of the least-frequent IDs. I made it 3 so that you could see that three tied for least-frequent.