pythonpandasmatplotlib-venn

Plot venn diagram with pandas and matplotlib_venn


I'd like to plot venn diagrams based on my pandas data frame. I understand that matplotlib_venn accepts sets as input. My dataset contain client id and two other columns with information if the client was in campaign or not.

df_dataset = pd.read_csv('...path...',delimiter=',',decimal=',')
campaign_a = df_dataset[(df_dataset['CAM_A'] == 1)] 
campaign_b = df_dataset[(df_dataset['CAM_B'] == 1)]

plt.figure(figsize=(4,4))
set1 = set(campaign_a['CLI_ID'])
set2 = set(campaign_b['CLI_ID'])

venn3([set1, set2], ('Set1', 'Set2'))
plt.show()

However I get an error:

File "C:\Python27\Lib\site-packages\matplotlib_venn_venn3.py", line 44, in compute_venn3_areas areas = np.array(np.abs(diagram_areas), float)

TypeError: bad operand type for abs(): 'set'


Solution

  • I believe you need to pass 3 sets. Based on the code here, if you pass three subsets then they are transformed into a tuple before being passed to compute_venn3_areas, where np.abs can handle them. The case when you pass only 2 sets looks like an unhandled error.