How can I use list for being implemented in Venn diagram?

Viewed 33

I have 4 tables and I want to see the intersections inside them. I have read 4 different tables (in excel) like this

df = pd.read_excel (r'E:\Mydata1.xlsx')  
df1 = pd.read_excel (r'E:\Mydata2.xlsx') 
df2 = pd.read_excel (r'E:\Mydata3.xlsx') 
df3 = pd.read_excel (r'E:\Mydata4.xlsx') 

and then, I select only 1 column called project name that has in all tables to see the intersection like this

d1 = df[~df['Project Name'].isnull()].index.tolist()
d2 = df1[~df1['Project Name'].isnull()].index.tolist()
d3 = df2[~df2['Project Name'].isnull()].index.tolist() 
d4 = df3[~df3['Project Name'].isnull()].index.tolist() 

after that, I want to use the venn library to see the venn diagram because in my case it has 4 circles and I want to see the intersections of them.

from venn import venn
datas = {
    "Data1": {d1},
    "Data2": {d2},
    "Data3": {d3},
    "Data4": {d4},
}
venn(datas) 

But, I have an error message like this

Untitled-1.ipynb Cell 12 in <cell line: 3>()
      1 from venn import venn
      2 datas = {
----> 3     "Data1": {d1},
      4     "Data2": {d2},
      5     "Data3": {d3},
      6     "Data4": {d4},
      7 }
      8 venn(datas)

TypeError: unhashable type: 'list'

I know when I've read some articles, we can't use list in hash(), But I don't know what should I do with this. Here's the venn source https://github.com/LankyCyril/pyvenn

1 Answers

You want to use set in your datas dictionary instead of {}.

datas = {
    "Data1": set(d1),
    "Data2": set(d2),
    "Data3": set(d3),
    "Data4": set(d4),
}

For example:

from venn import venn

d1 = ["A", "B", "C"]
d2 = ["B", "C", "D"]
d3 = ["A", "D", "E"]
d4 = ["C", "D", "E", "F"]

datas = {
    "Data1": set(d1),
    "Data2": set(d2),
    "Data3": set(d3),
    "Data4": set(d4),
}

venn(datas)

enter image description here

Related