0

Looking to use for loops to complete a conditional probability. Here's my dataframe:

 make model type rating
0    f     f    c      A
1    f     f    c      B
2    f     f    s      C
3    f     f    s      A
4    f     f    s      B
5    f     f    s      B

I can separate the rows by 'rating', but then need to find the conditional probability for the type|rating. Where I'm struggling is that for a rating of C, there is no 'c' type, but I need to display it still in my output. I am looking get a count of 'type', then I can divide it by the len(rating). Output should look like this.

Prob(type=c|rating=A) = 0.500000
Prob(type=s|rating=A) = 0.500000
Prob(type=c|rating=B) = 0.333333
Prob(type=s|rating=B) = 0.666667
Prob(type=c|rating=C) = 0.000000
Prob(type=s|rating=C) = 1.000000

Thanks!

Zero
  • 74,117
  • 18
  • 147
  • 154

0 Answers0