I have the following DataFrame where each column represents a categorization algorithm for the items in the index (a,b, …)
df = pd.DataFrame(index = ['a', 'b', 'c', 'd', 'e', 'f', 'g'])
df['A'] = ['a1', 'a1', 'a2', 'a2', 'a3', 'a4', 'a4']
df['B'] = ['b2', 'b2', 'b2', 'b1', 'b4', 'b3', 'b3']
df['C'] = ['c4', 'c4', 'c4', 'c3', 'c2', 'c2', 'c1']
df:
A B C
a a1 b2 c4
b a1 b2 c4
c a2 b2 c4
d a2 b1 c3
e a3 b4 c2
f a4 b3 c2
g a4 b3 c1
I would like to reorder the category names in each column so that I can better assess whether the index items are being categorised similarly across columns.
Is there a way to visualise how the categories differ across columns? Something like a vendiagram.
Thank you in advance.
Here is my take on your interesting question.
Using Python standard library difflib module, which provides helpers for computing deltas, you can define a helper function.
The general idea is to rate similarities between rows using a unique identifier (based on all columns), and sort the dataframe from most similar to less similar rows.
Then, assign an arbitrary color to the first row (as a whole) and its individual values, and go through each row and either assign the previous color (if identical) or a new one (both to row itself and the values), so that, for instance,
c2in rowseandfhas the same color.And finally, in a Jupyter notebook cell, run:
Output: