I have an excel file with different cases and about 75 events for each case. There is a probability of each event happening given each case. So the excel file looks like this:
event1 event2 ... event75
case1 0.0343 0.0234 ... 0.1194
case2 0.0924 0.0532 ... 0.0023
I want to generate a random number in python, ranging from 0 to 75 with the probabilities of the given case. When I worked with cases with only 2 events that could occur, I used a code like this:
excel_cases = pd.read_csv('/.../cases.csv')
def event_probabilities(case):
event_probability = excel_cases.loc[excel_cases['Case'] == case, 'event1'].values[0]
return event_probability
event1_probability = event_probabilities("case1")
np.random.choice(np.arange(1, 3), p=[event1_probability, (1 - event1_probability)])
# can also do an event2_probability instead of 1-event1_probability
However when the range of events get bigger I don't know what would be a more efficient way of doing this. Thanks for the help.
*Not same as the other question as I'm getting the probabilities from Excel