Need help. I have Pandas DataFrame like:
Shown ID Bought ID
59,60,61,62,60,63,64,65,66,61,67,68,67 67,60,63
63,64,63,64,63,65,66 0
87,63,84,63,86 86
I need to find the number of occurrences of each number of each "Show ID" row in whole "Show ID" column.
So the expected result for "Shown ID" column is:
[[('59', 1), ('60', 2), ('61', 2), ('62', 1), ('63', 6),
('64', 3), ('65', 2), ('66', 2), ('67', 2), ('68', 1)],
[('63', 6), ('64', 3), ('65', 2), ('66', 2)],
[('87', 1), ('63', 6), ('84', 1), ('86', 1)]]
How to do that?
Then I need to create a list of lists with sorted values of each row of "Shown ID" column (each list of result list of lists above).
So summary result must be:
[['63', '64', '60', '61', '65', '66', '67', '68', '59', '62'],
['63', '64', '65', '66'],
['63', '87', '84', '86']]
How Can I do that? If the numbers have the same frequency of occurrences, it needs to sort in ascending appearing in list (the earlier appeared in row, the more priority)
This is how you can get what you are looking for:
output:
Values which have the same count might come in any order.
If you want to make column level counter then you can do it like this:
output