Probability is the measure of the likelihood that an event will occur in a Random Experiment. Event is the representation of a subset of the sample space (set of all possible results of the experiment). A random experiment is when we repeat similar procedures over and over, but they yield unpredictable results.
For the union of two events to occur, we must have the same sample space (S). Let’s consider two possible situations of the union of A with B (A U B).
A ∩ B = Ø
If the joint between sets A and B form an empty set, that is, the sets do not have terms in common (independent events), considering that the sample space is different from zero, we reach the following conclusion:
P(A U B) = P(A) + P(B)
If the joint between sets A and B form a non-empty set, it indicates that they have elements in common (dependent events), so the probability of the joint of these two sets can be defined as follows:
P(A U B) = P(A) + P(B) – P(A ∩ B)

Following the _laws of DeMorgan_, which proves that the complement of the union of two sets is equal to the joint of the complements of these sets:

Then, the complement of the union of three or more sets can be calculated as the product of the complements of these sets. The equation is expressed as follow:

So, we can get the union of the sets, getting the complement of the product of the complements of these sets.

The Application
From there, we demonstrate how to calculate the union of multiple sets from each group of a given dataset. Data were created randomly, considering that they represent the probability of some event happening, being categorized by an ID. After grouped by ID, a lambda function was applied to calculate the union of these sets for each group.
#import libraries
import pandas as pd
from random import seed
from random import random
from random import randint
#generate random data
seed(1)
id = []
prob = []
for _ in range(30):
value_id = randint(0, 10)
value_prob = random()
id.append(value_id)
prob.append(value_prob)
#create DataFrame
df = pd.DataFrame(prob, id, columns=['Probabilities'])
df.index.name = 'ID'
#grouping by ID
g = df.groupby(df.index)
#applying union function
g.apply(lambda x: 1 - (1 - x).prod())

Let’s assume that each probability represents the likehood that some device will fail. Also consider that there are 10 different device types and you want to know the probability that at least one of them will fail for each device type. This was exacly what the function made, each ID represents the union of these probabilities. Each probabilities would represent the likehood that at least one device of that type (ID) will fail.
Conclusion
The calculation of the function was based on the union equation for multiple sets considering the DeMorgan Law. The function was able to aggregate the data in the union of probabilistic events, showing the probability of a certain event occurring in each group. The function could be used for better decission making, providing a specific way to interpret the data.
References
Andy Hayes and Vincent Wu. De Morgan’s Laws. https://brilliant.org/wiki/de-morgans-laws/